From 03f89ec922f77795df0ee47d93104da3d1c7c31c Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Tue, 21 Feb 2023 16:11:03 -0500 Subject: [PATCH] DLL working under mingw --- luprex/Makefile | 8 +++++--- luprex/cpp/drv/driver-mingw.cpp | 12 +++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/luprex/Makefile b/luprex/Makefile index 85715670..7c484fca 100644 --- a/luprex/Makefile +++ b/luprex/Makefile @@ -9,8 +9,9 @@ ifneq "" "$(findstring -linux-,$(MAKE_HOST))" OS=linux EXE=luprex DLL=luprex.so - LIBS=-L./ext/openssl-mingw -lssl -lcrypto -ldl + LIBS=-L./ext/openssl-linux -lssl -lcrypto -ldl LUAFLAGS=-DLUA_USE_APICHECK -DLUA_USE_POSIX + LINKDLL=-export-dynamic -Wl,--no-allow-shlib-undefined -Wl,-z,defs -shared OPT=-g -O0 else ifneq "" "$(findstring cmd.exe,$(COMSPEC))" @@ -20,6 +21,7 @@ else ifneq "" "$(findstring cmd.exe,$(COMSPEC))" DLL=luprex.dll LIBS=-L./ext/openssl-mingw -lssl -lcrypto -lws2_32 -lcrypt32 -lcryptui LUAFLAGS=-DLUA_USE_APICHECK -DLUA_COMPAT_ALL + LINKDLL=-Wl,--no-allow-shlib-undefined -shared OPT=-g -O0 else @@ -125,10 +127,10 @@ GPP=g++ -Wall -fvisibility=hidden $(OPT) -std=c++17 -MMD all: $(EXE) $(DLL) $(EXE): $(OBJ_DRV) - $(GPP) -o $@ $(OBJ_DRV) -L./ext/openssl-linux -lssl -lcrypto -ldl + $(GPP) -o $@ $(OBJ_DRV) $(LIBS) $(DLL): $(OBJ_ERIS) $(OBJ_CORE) - $(GPP) -export-dynamic -Wl,--no-allow-shlib-undefined -Wl,-z,defs -shared -o $@ $^ + $(GPP) $(LINKDLL) -o $@ $^ obj/eris/%.o: ext/eris-master/src/%.c $(GPP) -fPIC $(LUAFLAGS) -o $@ -c $< diff --git a/luprex/cpp/drv/driver-mingw.cpp b/luprex/cpp/drv/driver-mingw.cpp index a1e4318e..8696f587 100644 --- a/luprex/cpp/drv/driver-mingw.cpp +++ b/luprex/cpp/drv/driver-mingw.cpp @@ -270,17 +270,11 @@ static void ssl_load_certificate_authorities(SSL_CTX *ctx) { CertCloseStore(hStore, 0); } -// Load the DLL if it's not already loaded. Stores -// the handle in a global variable. -static void load_engine_dll() { - // Not actually implemented yet. Currently, the engine - // is linked right into the executable. -} - static void call_init_engine_wrapper(EngineWrapper *w) { - load_engine_dll(); + HMODULE dll = LoadLibraryA(".\\luprex.dll"); + assert(dll != nullptr); using InitFn = void (*)(EngineWrapper *); - InitFn initfn = (InitFn)GetProcAddress(GetModuleHandle(NULL), "init_engine_wrapper"); + InitFn initfn = (InitFn)GetProcAddress(dll, "init_engine_wrapper"); assert(initfn != nullptr); initfn(w); }