LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   i want smaller executable with gcc ! (https://www.linuxquestions.org/questions/programming-9/i-want-smaller-executable-with-gcc-137178/)

thrix 01-21-2004 02: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 03: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 04: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 04:13 PM

For squeezing ELF executables to the extreme, see:

http://www.muppetlabs.com/~breadbox/...ny/teensy.html

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

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

UltimaGuy 01-22-2004 02: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 10:50 AM

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


All times are GMT -5. The time now is 09:03 PM.