I read everything here and everything that I can find on the network, but this information is outdated, contradictory or not applicable. I have a very simple C library that I compile to a shared library on Linux and everything works wonderfully. I want to pass this to a windows dll. I have not programmed Windows since the 1990s, but I don’t quite understand about some of its complications (indeed, that is why I use Linux :-).
The MinGW compiler line that generates the library is (generated by cmake):
gcc.exe -Wl,--export-all -Wl,--enable-auto-import -shared -o libonejoker.dll -Wl,--out-implib,libonejoker.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles/onejoker.dir/objects.a -Wl,--no-whole-archive -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
I don’t know why, or I need all these libraries, since I don’t call the OS at all, but cmake puts them there. This creates the dll and .dll.a. I told cmake to add -Wl, - export-all, although this should have been the default. Trying to link my simple test program with a newly created dll does the following:
gcc.exe -g @CMakeFiles/test004.dir/includes_C.rsp -o CMakeFiles/test004.dir/test004.c.obj -c /c/Users/Lee/Projects/OneJoker/src/tests/test004.c gcc.exe -g -Wl,--whole-archive CMakeFiles/test004.dir/objects.a -Wl,--no-whole-archive -o test004.exe -Wl,--out-implib,libtest004.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/C/Users/Lee/Projects/OneJoker/build/src/lib ../lib/libonejoker.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
If the program "test004" does not call any functions from the DLL, it works fine. As soon as I uncomment any line that calls any function from the library, it fails without even reaching main (). gdb does not give a stack trace, but says:
During startup program exited with code 0xc0000135.
Googling, which does not bring anything useful. Note:
- The code is in C, NOT C ++.
- The code does not contain __declspec () s or any other Windows isms; GCC docs pretty clearly imply that they are not needed, but other tutorials for creating DLLs put them. I want the DLL to simply export everything, just like on Linux.
- The compiler lines are generated by cmake, because I thought it would be easier to port, but I would gladly give up cmake if it was easier to just create Make files manually that do the right thing.
Any pointers in the right direction will be useful, including just pointing to Documents that are not outdated, and not for C ++.