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

前端 未结 14 2428
遇见更好的自我
遇见更好的自我 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:04

    I replicated your test using Cygwin and g++. Your code compiled to 480k with -O2. Running strip on the executable reduced it to 280k.

    In general, though, I suspect your problem is the use of the header. This causes a fairly large library to be linked in. Also, note that cout << x does a lot more than just printing. There are locales and streams and all sorts of under-the-hood stuff.

    If however, having a small executable size is a real, mission-critical objective, then avoid it and use printf or puts. If it's not, then I would say pay the one-time cost of iostream and be done with it.

提交回复
热议问题