Reducing the size of the binaries
Oscar Fuentes
ofv@wanadoo.es
Sat Sep 25 21:51:00 GMT 2004
Juan Ignacio Garzón <jigarzon82-chan@yahoo.com.ar> writes:
[snip]
> the result was:
> a .o file for the main.cpp (803 KB)
> a .o file for the .cpp (class definition) ( 810 KB)
> the .exe file (1251 KB)
>
> I'm using gcc 3.2 (mingw32)
> I cannot understand why are they so big in size... I
> think im doing something bad, but I don't know what...
First: use strip -s yourexecutablename.exe and see if that reduces
size.
Second: MinGW's libstdc++ is statically linked. This means that there
is a fixed size overhead for all executables that uses iostreams, for
instance.
> If I include stdlib.h in any file, it results in a 2
> MB exe.
I doubt that by merely #include'ing <stdlib.h> you obtain a 2 MB
exe. Does this program produces a 2 MB exe?
#include <stdlib.h>
int main() { return 0; }
> I have a lot of programs made with C++ and their
> binaries are smaller than mine, and mi program has
> less than 100 lines. What's wrong?
Those programs compiled with [Visual] C++ uses a dynamically linked
C++ Standard Library. My experience shows that, for medium to large
projects, MinGW and VC++ 6.x executable size tends to converge. VC++
7.x uses some clever tricks that can produce considerably smaller
executables under some common circumstances.
BTW, the correct place for discussing this topic is the MinGW users
mailing list, or other MinGW-related forum. This mailing list is for
discussing the development *of* GCC, not *with* GCC.
--
Oscar
More information about the Gcc
mailing list