GCC C++ “Hello World” program -> .exe is 500kb big when compiled on Windows. How can I reduce its size?

前端 未结 14 2360
遇见更好的自我
遇见更好的自我 2020-11-27 04:29

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

14条回答
  •  粉色の甜心
    2020-11-27 05:16

    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?

提交回复
热议问题