Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mingw build - depends on DLL not native to windows

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?

like image 975
J T Avatar asked Jun 09 '11 19:06

J T


2 Answers

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.

like image 152
eriktous Avatar answered Nov 18 '22 09:11

eriktous


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.

like image 29
0xC0000022L Avatar answered Nov 18 '22 08:11

0xC0000022L