Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-19-2004, 04:27 PM   #1
Registered: Jun 2004
Distribution: Slackware
Posts: 182

Rep: Reputation: 24
gcc optimization flags: rules of thumb

I've looked over some of the gcc optimization settings, such as -O2, -O3, etc., and tried to understand exactly what they do. What are some of the best settings to use? Are there any rules of thumb for what settings to use when compiling certain programs or kernels?
Old 06-19-2004, 04:49 PM   #2
Registered: Jun 2004
Location: Scotland
Distribution: Anything that'll install...
Posts: 305

Rep: Reputation: 30
There's a good section on optimisation flags in the Gentoo docs, you could also try
Old 06-20-2004, 12:18 AM   #3
Registered: Jun 2004
Distribution: Slackware
Posts: 182

Original Poster
Rep: Reputation: 24
I'm just a little wary of using the power of -O3, or maybe even -O2. What do slackware packages use by default?

[edit] I guess I should ask, what do the "official" slackware packages use by default? [/edit]

I think they're all stripped, just try to find an ELF executable in /usr/bin that's not.

Last edited by elyk; 06-20-2004 at 12:20 AM.
Old 08-04-2004, 11:49 PM   #4
LQ Guru
Registered: Apr 2003
Location: nottingham england
Distribution: Gentoo
Posts: 2,672

Rep: Reputation: 47
i dont know how i can possibly explain it any more simply than the gcc man pages.. but anyways..

-O0 = no optimisation
-O1 = perform optimisations that will not increace compile time significantly
-O2 = perform optimisations that will not increace binary size significantly
-O3 = apply all optimisations
-Os = optimise binary size, (almost as optimised as -O2)

rule of thumb....
if compile time is an issue, use -O1
if binary file size is an issue, but compile time is not, use -O2
if time, nor binary file size is an issue, use -O3
if file size IS an issue, use -Os
if you get seg faults, or have bad hardware, recompile with a lover optimisation.


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
TCP packet flags (SYN, FIN, ACK, etc) and firewall rules TheLinuxDuck Linux - Security 12 04-28-2005 11:30 PM
GCC 3.4/3.3 Optimization Flags monohouse Linux - Software 0 10-28-2004 10:48 AM
Best Optimization Flags for a 512mb (ddr) equipped Athlon XP 1.8 ghz? haimeltjnfg Linux - Software 4 08-30-2004 12:52 AM
optimization flags and kernel compiling kpachopoulos Linux - Newbie 2 08-26-2004 07:29 AM
GCC Processor Optimization ? Tomasfuego Programming 1 12-20-2003 02:59 PM

All times are GMT -5. The time now is 12:39 PM.

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