LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 05-03-2007, 12:35 AM   #1
matsko
Member
 
Registered: Dec 2005
Posts: 51

Rep: Reputation: 15
Compiling w/ CFLAGS=-O2


Usually when I compile my scripts from source I never use any compiler flags. After taking a look at this article I found

http://www.zrinity.com/developers/apache/apache2src.cfm

I noticed that they were using the CFLAGS=-O2 option. Is this compatible for fedora core and/or centOS? Do all gcc compilers have this feature, and if they do, is it safe?

Should I use it or should I avoid it?
 
Old 05-03-2007, 01:08 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,104

Rep: Reputation: Disabled
It's pretty common - if you optimize at -O3, you risk it having the opposite effect, but -O2 is safe and effective when used as directed. You could check the... I guess it would be source rpms... and probably find that fedora uses that already.
 
Old 05-03-2007, 12:49 PM   #3
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
i always use benchmarking and find the best optimization flags for my system.
the results can be remarkable.
example:
gcc -O2
tower of hanoi runs in 20 seconds
ggc -march=athlon-xp -O3 -ffast-math
tower of hanoi runs in 14 seconds

thats a 30% increase

overall those flags give about a 13% speed increase

it is very rare for optimization flags to cause problem but it does happen occasionally and is obvious and easy to correct. you just have to compile the app again without them.
 
Old 05-03-2007, 02:54 PM   #4
matsko
Member
 
Registered: Dec 2005
Posts: 51

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by digiot
It's pretty common - if you optimize at -O3, you risk it having the opposite effect, but -O2 is safe and effective when used as directed. You could check the... I guess it would be source rpms... and probably find that fedora uses that already.
Ok, but for compiling something from source, not rpm source, does fedora core already compile using that option by default?
 
Old 05-03-2007, 03:55 PM   #5
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,104

Rep: Reputation: Disabled
RH/Fedora is the one major distro I've always avoided, so I don't know anything about it. If I understand your question correctly, you want to know how fedora builds from source in order for it become an rpm in the first place? I don't know but searching the web should turn stuff up. For instance, this may help, though it looks old. It says "the default RPM build environment is located in /usr/src/redhat". And the man page for rpmbuild on the web says
Quote:
The command

rpmbuild --showrc

shows the values rpmbuild will use for all of the options are currently set in rpmrc and macros configuration file(s).
so that may give you some idea how rpms on your system would be built by default. I suspect that that would reflect what fedora does itself, though not necessarily so. And I'd be quite surprised if they didn't use some form of optimization.
 
Old 05-03-2007, 05:20 PM   #6
matsko
Member
 
Registered: Dec 2005
Posts: 51

Original Poster
Rep: Reputation: 15
Well my question was about building from source only. Therefore, nothing installed by package (like rpm).

So what I was asking is that does centOS (which is basically the same as FC) compile using CFLAGS=O2 by default, or do you have to set it up each time?
 
Old 05-03-2007, 06:28 PM   #7
studioj
Member
 
Registered: Oct 2006
Posts: 460

Rep: Reputation: 31
Quote:
Originally Posted by matsko
Ok, but for compiling something from source, not rpm source, does fedora core already compile using that option by default?
most source build systems do already incorporate -O2 as default
some packages even use -O3 as default.

i doubt if fedora changes the CFLAGS/CXXFLAGS away from what they are set to by the package developers

one of the most interesting gcc flags is -march
it allows gcc to create code for your processors specific modern instruction set.
otherwise you are by default using an instruction set for processors made 25 years ago.

-march for obvious reasons can't be included by default in generic distributions

also when you set CFLAGS or for c++ code CXXFLAGS as a shell variable the values are added usually in addition to other flags needed by the package.

Last edited by studioj; 05-03-2007 at 06:35 PM.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cflags bong.mau Programming 1 04-30-2007 11:08 AM
Where Do I Specify CFLAGS In Opensuse? lets-eat-gary Suse/Novell 1 01-09-2006 06:14 AM
Compiling Xmame - which CFlags in makefile? lets-eat-gary Linux - Games 2 03-12-2005 05:15 AM
cflags exodist Linux - Software 2 01-14-2005 07:44 PM
how to unset cflags? shanenin Linux - Software 4 01-25-2004 09:36 PM


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

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