Tip on how to reduce the size of GCC executables

Recently I was wondering about the huge size of the GCC executables which had a size of >200 KB for just printing out some text. As bubu rightly pointed out, this is just because of a statically linked runtime library.
At the weekend, I wrote some additional examples for the next release of irrKlang (to be released this week), and was able to reduce the size of the .exe files from about 250 KB to just 7 KB: I just removed the #include <iostream> statement and replaced the few calls to c++ streams with fprintf()'s and getch()'s.
update:the comment section in this entry is a bit destroyed somehow. TBD: repair.

eight comments, already:

Long live C, then. Nice find though… I’m looking forward to Irrklang on GCC :)
jasper - 08 01 07 - 19:29

wow, never realized how heavyweight iostream was….
buhatkj - 08 01 07 - 23:12

buhu? :) hehe
And why do you use old-style include’s: ?
Normally in C++ every include’s must be written without .h suffix – vector, string, iostream, set, map, ...
Without .h you won’t get std namespace (globals are bad… blah blah blah :)
bubu () - 09 01 07 - 01:55

Removing iostream and manually adding your functions might be fine for now, but it will become a nightmare later on in development when you need more functions in iostream. The solution is to use UPX- http://sourceforge.net/projects/upx It compresses dlls, exes, and libraries among other files. I have once achieved a 50:1 ratio using the -BRUTE flag. The downside is that it takes several minutes versus 20 seconds for the -BEST flag. Try it out and see how it works.

BTW, can’t wait for Irrklang and GCC- I have been waiting for it since the first release. :-)
3ddev () - 09 01 07 - 08:03

I’d also echo bubu’s comment. Is there any difference in size when changing using the standard iostream header instead of iostream.h?

Probably not, but maybe it’s worth a try.
PeterM () - 09 01 07 - 08:08

The C++ standard library (libstdc++.so under Linux) is statically linked with Mingw/gcc under Windows. This does noticably increase the binary size, you won’t get around this. OTOH this avoids the necessity of providing a DLL which would be only used by gcc compiled executables.
The only useful way to overcome this size increase would be too link against the MS stdc++ dlls which should be available on every Windows system. But that’s not easily possible with gcc and might introduce lots of other problems.
So better don’t care for this little size increase and write good C++ programs which can compete with MSVC binaries in terms of maintainability :-)
hybrid - 09 01 07 - 09:41

The link for mingw explaining all this:

Name:  
Remember personal info?
yes
no
Email (optional):
URL (optional):
Enter "layered" (antispam):
Comment:Emoticons / Textile

  ( Register your username / Log in )

Notify: Yes, send me email when someone replies.  

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Note: If you type in your email adress above, it will be visible to other visitors, although it will be hidden for bots using javaScript.