How to reduce the size of executable produced by MinGW g++ compiler?

后端 未结 4 797
情书的邮戳
情书的邮戳 2020-11-30 11:07

I have a trivial \"Hello world\" C++ program that is compiled to 500kB executable by MinGW g++ compiler under Win XP. Some say that is caused by iostream li

4条回答
  •  盖世英雄少女心
    2020-11-30 11:31

    Flags to use:

    • -s like you've been doing to strip symbols
    • -lstdc++_s to specify dynamically linking against the libstdc++.dll
    • -Os to optimize the binary for size.

    By default mingw static links to libstdc++.a on Windows.

    Note that the lstdc++_s flag is only in MinGW with GCC > 4.4, I believe.

提交回复
热议问题