DLL with no compiled dependencies

63 views Asked by At

I am trying to compile a DLL with mingw32 (x86_64-w64-wingw32-gcc) in the smallest way possible.

I have an executable client running that has all of the dependencies that the DLL would need, like json.c and base64.c.

Instead of compiling json.c and base64.c into the DLL, I would rather find a way to ignore the "undefined reference" errors and let the DLL pull functions from the executable client's json.c and base64.c.

Thus, my question. How do I compile this zero-dependency DLL using mingw?

I've tried -Wl,--unresolved-symbols=ignore-all but it doesn't work. The option is valid... but the GCC error output is the same.

Here, I have an exectuable running with printSuccess function defined and I am trying to compile this DLL to have an unresolved symbol that will be called with __declspec(dllimport) when the DLL does DLL_PROCESS_ATTACH that should (hopefully) launch printSuccess once I LoadLibrary & GetProcAddress.

This is the output:

dev@CLIENT2:/$ x86_64-w64-mingw32-gcc main.c -Wl,--unresolved-symbols=ignore-all -o main64.exe

main.c: In function ‘main’:
main.c:10:2: warning: implicit declaration of function ‘printSuccess’ [-Wimplicit-function-declaration]
   10 |  printSuccess();
      |  ^~~~~~~~~~~~
/usr/bin/x86_64-w64-mingw32-ld: /tmp/cctVzHaX.o:main.c:(.text+0x15): undefined reference to `printSuccess'
collect2: error: ld returned 1 exit status
1

There are 1 answers

3
rgnt On

Well because compiler needs the functions to be present when linking, because the addresses have to be looked up, what you are trying to do is impossible.

My recommendation is to actually move the json and base to different module, which then can be depended on by executable and the other DLL.