Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-21-2004, 03:42 PM   #1
Registered: Jan 2004
Location: Nove Zamky > Slovakia
Distribution: Slackware 9.1
Posts: 57

Rep: Reputation: 15
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
Old 01-21-2004, 04:27 PM   #2
Mega Man X
LQ Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 64
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
Old 01-21-2004, 05:06 PM   #3
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
try the -s flag to strip the binary of it's symbols, you'll be amazed how much it cuts out.
Old 01-21-2004, 05:13 PM   #4
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
For squeezing ELF executables to the extreme, see:
Old 01-21-2004, 07:31 PM   #5
Senior Member
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
Hko: thats a great link you pointed to. thanks.
Old 01-22-2004, 03:08 AM   #6
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 31
You can also use the 'strip' command on the executable to strip out unwanted compiler flags and debugging info.
Old 01-22-2004, 11:50 AM   #7
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
*cups hand around mouth: "echo .. echo"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a Java executable class from another executable class LUB997 Programming 22 07-24-2005 05:57 AM
Problem with gcc: configure: error: C compiler cannot create executable abefroman SUSE / openSUSE 4 05-11-2005 07:12 PM
Executable compiled w/gcc won't run brancheb Programming 5 05-16-2004 02:56 PM
gcc can't create executable Aeion Linux - Newbie 1 04-06-2004 01:03 PM
To big executable with gcc thrix Programming 8 01-22-2004 05:43 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:39 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration