Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22199

Building simple DLL with MinGW

$
0
0

I've read everything here and everything I can find on the net about doing this, but the information is out-of-date, contradictory, or inapplicable. I have a very simple library in C, which I compile to a shared library in Linux, and all works wonderfully. I want to port this to a Windows DLL. I haven't programmed Windows since the 1990s, but I'm not totally clueless about its complications (indeed, they are the reason I use Linux :-).

The MinGW compiler line that generates the library is this (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

Not sure why or if I need all those libraries since I'm not making any OS calls in the library at all, but cmake puts them there. This creates the dll and the .dll.a. I told cmake to add the -Wl,--export-all, though that's supposed to be the default. Attempting to link my simple test program with the newly created dll does this:

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.cgcc.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 silently without even getting to main(). gdb gives no stack trace, but says:

During startup program exited with code 0xc0000135.

Googling that doesn't turn up anything useful. Please note:

  • The code is all in C, NOT C++.
  • The code does not contain __declspec()s or any other Windows-isms; the GCC docs pretty clearly imply that they aren't necessary, but other tutorials on creating DLLs put them in. I want the DLL to just export everything like it does on Linux.
  • The compiler lines are generated by cmake, since I thought that would make it easier to port, but I'd happily abandon cmake if it's easier to just hand-build Makefiles that do the right thing.

Any pointers in the right direction would be helpful, including just pointing me to Docs that are not out-of-date and not for C++.


Viewing all articles
Browse latest Browse all 22199

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>