I'm compiling my library for export as a shared library using MinGW (GCC 4.5.0). I do this by compiling all the source files using MAKE commands similar to:
gcc -shared -c mysource.cpp -o mysource.o
And then finally:
gcc -shared -lstdc++ -lm -lws2_32 mysource.o -o mylib.dll
When I do a dependency walk of my output file (using http://www.dependencywalker.com/ for example), I see that there are 3 dependencies:
KERNEL32.dll
MSVCRT.dll
LIBSTDC++-6.DLL
Having my DLL depend on files that don't ship with windows is sub-optimal for my end goal.
Is there a way I can setup my system up so that the final output (DLL) ONLY depends on KERNEL32 and MSVCRT?
The -static
flag may be what you're looking for. (It still looks funny to me to use both -static
and -shared
on the same line, but they are not opposites.)
If you would use g++
as a driver instead of gcc
, you could instead use the -static-libstdc++
flag.
Well, it's exactly what you told your linker to do with -lstdc++
... perhaps move that parameter before the -shared
and link again. To my knowledge that should use the static version of the C++ standard lib then.
Note: I think there was also a good reason to prefer g++ for C++ targets rather than using gcc. Probably it was about the inclusion of the C++ standard lib. Can't remember it from the top of my head. Also, I don't know whether MinGW differs in that case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With