Reputation: 1926
I have a project that's not really big. With Visual Studio's C++ compiler the executable is 100+KB. But with mingw GCC it goes up to 500+ KB. Same thing happens on Linux. That's for the release build. For debug build GCC produces 1.4MB while VS's C++ compiler only produces 400+KB. What's the reason that causes such a huge discrepancy? Does it have anything to do with static/dynamic linking? What can I do to reduce the executable size produced by GCC?
Upvotes: 3
Views: 2584
Reputation: 210352
Did you pass the -s
flag to GCC?
Is Visual Studio linking with the CRT statically or dynamically? How about GCC? It's likely that VC is linking dynamically (/MD
flag, instead of /MT
) whereas GCC is linking statically (-static-libgcc
flag, and otehrs)... try making them consistent and then seeing if there's a difference.
One way to tell is to check if your VC-linked executable depends on msvcr80.dll
(or a different version), and to see if your GCC-linked executable depends on some mingw
DLL. If they do, then they're dynamically linked; if they truly run standalone, then they're statically linked.
Upvotes: 1
Reputation: 24375
See this page on how to shrink GCC output size: http://wiki.wxwidgets.org/Reducing_Executable_Size
Upvotes: 2