Tip on how to reduce the size of GCC executables

Posted on:January 08 2007

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.





Comments:


Long live C, then. Nice find though... I'm looking forward to Irrklang on GCC :)
jasper
Quote
2007-01-08 19:29:00


wow, never realized how heavyweight iostream was....
buhatkj
Quote
2007-01-08 23:12:00


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
Quote
2007-01-09 01:55:00


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
Quote
2007-01-09 08:03:00


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
Quote
2007-01-09 08:08:00


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
Quote
2007-01-09 09:41:00


The link for mingw explaining all this:
http://www.mingw.org/mingwfaq.shtml#faq-C++size
hybrid
Quote
2007-01-09 11:03:00


ah, sorry for the typos. Of course I meant 'bubu' and 'iostream' not 'iostream.h'. Corrected.
niko
Quote
2007-01-09 18:55:00


Add comment:


Posted by:


Enter the missing letter in: "Internat?onal"


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons