MinGW binary 3x as big as MSVC binary

I'm currently porting a library (not written by myself, I'm "only" porting it) to use the MinGW compiler. The library is a real heavyweight, with all kinds of C++ "black magic" (multiple inheritance, templates of templates of templates, very macro heavy, etc.).

Now, after some weeks, I get everything compiled fine and it also seems to work well (unit tests work, as do the demos).

What bugs me, though, is the sheer size of the MinGW binaries in contrast to the MSVC binaries. I know that MinGW binaries are generally slightly bigger due to having to include the own non-MS system libraries, but we're talking about 33 MB for MinGW vs 13 MB for MSVC. And that is the "release" (-O3 and -s flags) version!

Those are the flags I compile with in MinGW:

-c -O3 -s -MMD -march=native -frtti

And for the linker it is this:

-shared -s -static-libgcc -static-libstdc++ 

I know that rtti adds some size, but it also has to be in the MSVC binaries. And the static libgcc and libstdc++ libraries can't be that big... or can they?

What am I missing here? Normally, the size difference between MinGW and MSVC isn't that big.


First off, who cares? Have you seen this larger size to impact performance?

Second: are you sure you're linking statically with MSVC? Check with Dependency Walker to be sure.

Third: yes MinGW GCC compiled binaries are generally larger. This is because MinGW provides a part of the C library to make up for how ridiculously broken msvcr* is compliance-wise. This has never shown as a large difference for me though.

Fourth: template and inline handling can differ between the two compilers.

Fifth: have you tried to compile the GCC version with -fno-keep-inline-dllexport and/or -Os?


I experienced this issue once and for me it turned out to be just what rubenvb suggested- the C/C++ std library was being statically linked in MinGW, but dynamically linked in MSVC. I used "dumpbin /imports" on each compiled executable/dll to determine this. If you don't see MSVC*.dll as an import, its linked statically. You can link the std libs statically in MSVC by changing the "Runtime Library" setting in Visual Studio, which is a flag to cl.exe that is either /MT (for static) or /MD (for dynamic). I think it is dynamic by default.

链接地址: http://www.djcxy.com/p/41896.html

上一篇: 创建一个用于VB exe的Mingw DLL

下一篇: MinGW二进制3x与MSVC二进制一样大