-   Programming (
-   -   i want smaller executable with gcc ! (

thrix 01-21-2004 03:42 PM

i want smaller executable with gcc !
Here's my problem:
How should I optimize my program in RedHat 9.0 with gcc, to compile
a smaller code? I've compiled a very simple program with gcc in RedHat 9.0 and the code size was 12kB. In Debian and Knoppix i've compiled it to 4kB. How should I optimize my gcc in RedHat to produce such a little code. Is there any debug info in that 12kB executable, or what? Thanx for help

Mega Man X 01-21-2004 04:27 PM

Hi thrix!

I think it's more a matter of which gcc you are using then the distribution. Still, to optimize the code, usually we use -O3, example:

gcc -O3 -o helloworld helloworld.c

But the executables will be about the same size

infamous41md 01-21-2004 05:06 PM

try the -s flag to strip the binary of it's symbols, you'll be amazed how much it cuts out.

Hko 01-21-2004 05:13 PM

For squeezing ELF executables to the extreme, see:

h/w 01-21-2004 07:31 PM

Hko: thats a great link you pointed to. thanks.

UltimaGuy 01-22-2004 03:08 AM

You can also use the 'strip' command on the executable to strip out unwanted compiler flags and debugging info.

infamous41md 01-22-2004 11:50 AM

*cups hand around mouth: "echo .. echo" :D

All times are GMT -5. The time now is 02:55 PM.