I just recently started learning C++ - I am using nuwen\'s version of MingW on Windows, using NetBeans as an IDE (I have also MSDN AA Version of MSVC 2008, though I don\'t u
How is it that other compilers like msvc8 or even an order compiler like borland c++ 5.5.1 are capable of producing very small executables but mingw gcc isn't able to?
I did a quick compile of a 'hello world' for each of the following toolsets and observed the compiled executable size. Please note that in all these cases the runtime library is statically linked and all debug symbols have been stripped:
compiler toolchain exe size exe size
(w/iostream header) (w/cstdio printf)
-------------------------------------------------------------------------
Borland C++ 5.5.1 110kbyte 52kbyte
MSVC 2008 express 102kbyte 55kbyte
MinGW- GCC 3.4.5 277kbyte <10kbyte
MinGW- GCC 4.4.1 468kbyte <10kbyte
What's interesting is the later version of gcc 4.4.1 produces an even larger executable than gcc3.4.5, probably due to different version of libstdc++.
So is there really no way to remove dead code during the linking phase for mingw?
The major part of the size stems from the use of fairly extensive runtime libraries. So in real life you are actually linking a very large piece of 'dead code' if you have such a simple application.
As far as I know there are no linker flags to skip the unused parts of a linked library.
There are two ways I know of to fake a smaller application: