This is the mail archive of the
mailing list for the GCC project.
Re: Reducing the size of the binaries
Juan Ignacio GarzÃn wrote:
> Hi i'm compiling a very simple program that consists
> in 3 files:
> -a .h file (20 lines of code), which declares a class
> and includes iostream
> -a .cpp file (33 lines of code), including only the .h
> -main.cpp (11 lines), which includes only the .h.
> So, as you can see, its a very very simple program
> with 1 class and a main. I'm just beginning a proyect.
> When I compiled this using the following command line:
> g++.exe -c ... -o ... -I ... -DDEBUG -Wall -pedantic
> -g -ansi -fno-inline
-g is a request for debug symbols. These are huge, because you when you
#include iostream, debug symbols for your application involves the debug
symbols for a pretty fair chunk of the templates in libstdc++ :-)
> 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...
> If I include stdlib.h in any file, it results in a 2
> MB exe.
> 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?
They don't have debug symbols turned on (in fact, if you're looking at
release stuff, they probably have been run through 'strip' and don't have
any symbols at all except those needed to resolve linkage to DLLs).
Also note that at -O0 (the default, no optimization) binaries are likely to
be larger and slower than at -O1 (quick optimizations, don't slow the build
down too much), -Os (specifically optimize for size), or -O2 (optimize for
speed, most often used). -O0 mode is rather naive in it's code generation,
and is usually either to make the compile go fast or to make the code easy
for a debugger to follow.
> Thanks in advance...
> 100mb gratis, Antivirus y Antispam
> Correo Yahoo!, el mejor correo web del mundo