Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

When I compile a program, will the binary be CPU dependant?

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
Haakin
LXF regular


Joined: Tue Jun 21, 2005 10:40 am
Posts: 287
Location: Lleida (Spain, Europe)

PostPosted: Tue Jun 21, 2005 10:49 am    Post subject: When I compile a program, will the binary be CPU dependant? Reply with quote

Hello!

This is my first entry in this forum and English is not my mother tongue so, please, be indulgent.

I have this silly question. When I compile a program usually I do:

./configure
make
checkinstall

instead of make install. I'll do that to create an RPM because it will be a lot easier to remove the program in the future. When I compile a program in my PC (1 GHz AMD CPU, ./configure says that it is an i686), will it work in a PC with a different CPU?

Thanks in advance,

Javier
Back to top
View user's profile Send private message
M-Saunders
LXF regular


Joined: Mon Apr 11, 2005 1:14 pm
Posts: 2893

PostPosted: Tue Jun 21, 2005 10:55 am    Post subject: RE: When I compile a program, will the binary be CPU dependa Reply with quote

It should do, if it's just configuring for general 686 instructions -- eg -march=i686 instead of -march=athlon-4 or whatever. You can set the CFLAGS and CXXFLAGS environment variables before the ./configure step to make sure:

# export CFLAGS="-O2 -march=i686"
# export CXXFLAGS="-O2 -march=i686"

That'll make all C and C++ code compiled with common 686 CPU instructions rather than anything specific. You could even change that to 'i386' above for absolute maximum compatibility -- will be a slight performance drop though.

M
Back to top
View user's profile Send private message Visit poster's website
jjmac
LXF regular


Joined: Fri Apr 08, 2005 2:32 am
Posts: 1996
Location: Sydney, Australia

PostPosted: Tue Jun 21, 2005 12:59 pm    Post subject: RE: When I compile a program, will the binary be CPU dependa Reply with quote

Just to follow on the above,

You cpu will be compatable with anything compiled to its' level and below. But not to something compiled for a cpu above its' level. So for yours , an i686 compatible amd processor, that would be ...

i386, i486, i586 and i586

Are you thinking of any particular processor ?


jm
_________________
http://counter.li.org
#313537

The FVWM wm -=- www.fvwm.org -=-

Somebody stole my air guitar, It happened just the other day,
But it's ok, 'cause i've got a spare ...
Back to top
View user's profile Send private message
Haakin
LXF regular


Joined: Tue Jun 21, 2005 10:40 am
Posts: 287
Location: Lleida (Spain, Europe)

PostPosted: Tue Jun 21, 2005 3:15 pm    Post subject: RE: When I compile a program, will the binary be CPU dependa Reply with quote

No, I'm not. It's pure and simple curiosity.

I compile software when I cannot find a binary for my distro (SUSE 9.2), as Octave. I don't share these binaries.

In my box I need several hours to compile Octave. So, I was thinking if the RPM I got will be compatible with other CPUs. In that case I could just install my RPM instead of compiling it in every machine.

After running ./configure, one of the outputs is:
"Octave is now configured for i686-pc-linux-gnu"

So, I understand that the program will be compatible with i686 CPUs. To make sure that is compatible with i586 I should use:

# export CFLAGS="-O2 -march=i586"
# export CXXFLAGS="-O2 -march=i586"

Have I understood it?

Thanks for your help,

Javier
_________________
English is not my mother tongue. So, be ready to read bad grammar and limited vocabulary Sad
Back to top
View user's profile Send private message
jjmac
LXF regular


Joined: Fri Apr 08, 2005 2:32 am
Posts: 1996
Location: Sydney, Australia

PostPosted: Fri Jun 24, 2005 1:18 pm    Post subject: RE: When I compile a program, will the binary be CPU dependa Reply with quote

The rpms' are usually compiled down to i586 generally anyway, as i remember it. I think some distros will do "-mcpu=i686 -march=i586", deb likes to set it all at "i386" ... If you pipe the compiler output to a file "make 2>&1 |tee make-out" the clis' used should reveal whats going on there. The hint can be seen in the rpm name as well. In that, the file should have its' compile level expressed as part of its' name.

The main thing though is that a cpu is designed to be backward compatable. So, an i686 should run anthing up to and including i686. Which gives you the whole rang. An i585 processor, like a standard pentium, will likely have problems with a program compiled for an i686, but will do i386 to i586.

The "-march=" switch is the sensitive one, if the "-mcpu=" switch isn't given, it will imply it. It will determine the type of cpu level native code to assemple for. So an earlier processor will likely not have the instuctions that the program will want to use, if the compile is above the earlier processors level.

The "-cpu=" swich sets the scheduling level to use. If the processor dosen't have those scheduling levels/coded facilities, then they just wont be used. But it wont interfer with the programming being run. But if they are available, then they can be taken advantage.

If i'm remembering correctly, i think thats why some distros will compile their rpms for a i586 "-march=", but will schedule for an i686 "-mcpu=". That used to confuse me a bit, i would have thought the "-mcpu=" switch was referening to the assembled instuction set, but i was wrong, it is the "-march=" one.

There are other switches that may be used that will imply both. Such as "-mpentium" or is i, "-pentium=" for an i586, "-mathlon", -"athlonk7" etc.

The man and info pages have a lot of stuff on this, but, if you can navigate through those files with getting really irratated, you will be doing well Smile


>>
So, I understand that the program will be compatible with i686 CPUs. To make sure that is compatible with i586 I should use:

# export CFLAGS="-O2 -march=i586"
# export CXXFLAGS="-O2 -march=i586"
>>

That will set the assemble micro-code to be of that used by a standard "pentium", it will run on a i586, i686, or any of the athlons. It wont be suitable for anything below an i586, such as i486 or i386. It will also imply the "-mcpu=" scheduling level used should also be for the i586.



jm
_________________
http://counter.li.org
#313537

The FVWM wm -=- www.fvwm.org -=-

Somebody stole my air guitar, It happened just the other day,
But it's ok, 'cause i've got a spare ...
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast