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
Well when you use C++ standard library, exe can get big really quickly. If after stripping debug symbol, you still want to reduce the size of your software, you can use a packer like UPX. But, be warned, some antivirus choke on exe packed with UPX as some virus used it a long time ago.
If you need small executables, Tiny C will compile a 1536 bytes executable for a printf("Hello world!") TinyC is only C, not C++ and is known to compile faster and give slower executables than gcc.
EDITED: I have just tried a cout<"Hello World!" in DevC++ (bundles Mingw 4.8 and an Ide) and i got a 4,5 MB executable!!
You get the C++ standard library, and other stuff I guess, statically linked in as mingw has its own implementation of these libraries.
Don't worry so much about it, when you make more complex program, the size won't grow accordingly.
Very late answer, but maybe helpful for new c++ users that ended here searching for "reducing hello world binary size":
Here's the steps I've done to compile a hello_world.exe
with ~20KB:
#include <cstdio> // not <iostream>
int main()
{
printf("Hello, World");
return 0;
}
g++ -s hello_world.cpp -o hello_world.exe
upx -9 hello_world.exe
File size Ratio Format Name
-------------------- ------ ----------- -----------
40448 -> 20992 51.90% win64/pe hello_world.exe
You could use -s, which I believe is built into mingw as well. A simple hello world application compiled using g++ 3.4.4 on cygwin produced executable that was 476872 bytes, compiling again with -s (strips unnecessary data), reduced the same executable to 276480 bytes.
The same hello world application on cygwin using g++ 4.3.2 produced an executable of 16495 bytes, using strip reduced the size to 4608 bytes. As far as I can see, probably best to use more recent version of g++.
MingW has just released gcc 4.4.0, so if the executable size is important then I'd consider using that. As it indicates -s will probably help strip much of the debugging information out for you, that is only recommended if it is for production use.
If you use the "nm" utility or some other program that shows whats in your .exe, you'll see that it contains tons of classes that someone might want to use, but that you don't.