Reputation: 5126
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?
Upvotes: 9
Views: 6989
Reputation: 21
I believe the correct answer is "NO." Other people answering this have not attempted to solve your issue. I'd be delighted to be shown how I am wrong but I have exhaustively investigated this and at a minimum, both MINGW
and CYGWIN
environments seem to require distribution with a windows specific dynamic linked library (dll).
For Cygwin64 I compile using "g++" with these flags:
FFLAGS = -g -Wunused-variable -static -static-libgcc -static-libstdc++
but the executable still requires distribution with "cygwin1.dll"
-- I very much agree this is sub-optimal and I don't understand the limitation. I have found similar issues in MINGW
.
Upvotes: 2
Reputation: 6649
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.
Upvotes: 7
Reputation: 21259
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.
Upvotes: 1