[SOLVED] GCC and G++ build results if the -march=TYPE is not specified
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Ubuntu: An Absolute Beginners Guide
Ubuntu is a free, open-source computer operating system with 20 million users worldwide.
This 30 page guide was written for beginners and will tell you everything you need to know about the Ubuntu experience. You will learn how to install and setup Ubuntu on your computer, find technical support in your community, understand the Ubuntu philosophy, navigate the Unity desktop interface and use Ubuntu compatible software programs.
Click Here to receive this Complete Guide absolutely free.
GCC and G++ build results if the -march=TYPE is not specified
Hi. I'm sure this has been covered somewhere before, but I couldn't find anything and so figured I would post here.
I have been using Linux OSes for the past couple of years and also using GCC/G++ for application development. However, I have almost always been on x86 systems and never gained much experience using the wide range of optimization options available.
My question is, if I do not specify the -march=PROCTYPE option, will GCC still be able to detect the current architecture and build the code accordingly? I primarily ask this because I am working with an x86_64 system, and specifying -march=x86_64 in my makefiles generates errors about it being an unknown processor type, even though the CPU and OS are X86_64.
I know this sounds like a newbie question, but it's just ground I've never had to cover before until now. Any advice is appreciated!
x86_64 isn't a proper arch type for the march option. If you're using a GCC newer than 4.3 you should be able to use -march=native. For more information on how -march and -m work together I've written a small article on the matter: http://www.alunduil.com/2009/12/18/o...gentoo-cflags/.
x86_64 isn't a proper arch type for the march option. If you're using a GCC newer than 4.3 you should be able to use -march=native. For more information on how -march and -m work together I've written a small article on the matter: http://www.alunduil.com/2009/12/18/o...gentoo-cflags/.
Alunduil, thanks for the swift response! The info and the link were definitely helpful. I believe my previous source that told me x86_64 was valid was outdated.
Something else I was wondering: what happens if the -march option is not specified at all? The code still builds fine without it, but I have no way of telling if it is 32 or 64 bit.
Something else I was wondering: what happens if the -march option is not specified at all? The code still builds fine without it, but I have no way of telling if it is 32 or 64 bit.
Assuming that your gcc's backend is x86_64 and you specified the -m64 option to generate 64-bit code, if you don't use the -march= option for gcc/g++, you'll get code generated for a common subset of x86_64 CPUs, meaning that it should run on a wide range (all) of x86_64 systems, but you possibly don't get all the optimizations/features which your specifc (local) CPU provides.
So, gcc always has a default path even if the user doesn't specify a concrete option. :-)
Right, the file command is absolute correct. It will display the ABI used. Just for your interest, the file command looks at the first bytes of the executable to determine what kind of executable format is used and which ABI is used. The default executable format on Linux is ELF and you'll get the ELF-ABI by using
That's all great information but I want to specify that the extra instruction sets that modern CPUs might have available are not going to be used at all to get the common CPU instructions that would run on a generic-x86_64.
Oh, sh**! :-) I went through the code and finally found the mistake. Although it isn't (yet) documented in the man page, the correct switch name is -march=x86-64 to get the default setting. The difference between the dash and underscore was just too marginal to catch it in the first instance.
There already was a discussion on the GCC mailing list about the confusion by x86-64 and x86_64 (http://gcc.gnu.org/ml/gcc/2006-03/msg00229.html), but unfortunately without any result why x86_64 isn't allowed.
I think this needs to be changed in the documentation ...
Last edited by ForzaItalia2006; 05-25-2010 at 06:27 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.