The compiler used by DevC++
Mingw, does things a little differently compared for VC++ for example.
When you include <iostream> for example so you can use cout, cin, cerr etc., you end up including a whole bunch of stuff. It doesn't matter if you actually use the stuff, you still take a file size hit.
For example:
Code:
#include <iostream>
int main() {
} That will be 463KB with Mingw 3.4.2.
With VC++ 2003 toolkit, it'll be 21.5KB
For Mingw, one thing you can do is use the linker option -s to stripp all debugging info. That will shrink the file size in half a lot of the times. You can also use the -Os option to optimize for file size.
Besides that, there's not much you can do except pack the exe with
upx.
For example, a command to compile file.cpp might look like this.
g++ -Wall -Wextra file.cpp -o file -Os -s && upx --best file.exe
That will usually bring your exe down to 80KB.
However, packing an exe means that it has to be unpacked in memory when you load it. This *could* decrease startup times of the app. (Although I've never seen it make a differerence.)
You can also avoid the STL and just use C methods, but that would defeat the purpose of using c++ methods.
If you look in the iostream file for mingw, you'll notice: static ios_base::Init __ioinit.
That call tells the linker to include everything needed to use cout etc.
Roughly, when you include <iostream>, it's like in your code, you're using everything Iostream supports. Other compilers only account for what you use.
The file size hit for mingw evens out as apps get bigger and to put simply, if you need to distribute an exe, zip it up or distribute it via an installer that uses good compression.
Just as another example, if you don't include <iostream>:
Code:
#include <cstdio>
int main() {
} Mingw will compile that at 15KB and if you strip it, it'll be 5.5KB.