After programming for a while in C, I decided to finally start to learn C++. This is sort of bothering me, as the standard ‘hello world’ in C is usually ~16KB, including all of the crud your compiler throws on there. (Using stdio)
However, when I create a C++ executable doing hello world, the file is ~470KB! I went ahead and used cstdio instead of iostream, thinking it would make a difference and it did.
My question is:
When I include iostream, why does the size of my executable explode?
Edit: I’m using G++ (With the Dev-CPP IDE, but I can figure out how to add CL paramaters)
In a word, symbols.
The C++ standard library introduces a lot of symbols to your program, since most of the library exists primarily in the header files.
Recompile your program in release mode and without debug symbols, and you can easily expect the program to be significantly smaller. (Smaller still if you strip symbols.)
As a quick demonstration of this fact, observe:
I can’t explain why a Windows build of the programs with G++ produces such large executables, but on any other platform, symbols are the primary driving factor in large file sizes. I don’t have access to a Windows system at the moment, so I can’t test.