compiling a C++ program using g++ with x86 settings on x86_64
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
These -m switches are supported in addition to the above on AMD x86-64 processors in 64-bit environments.
-m32
-m64
Generate code for a 32-bit or 64-bit environment. The 32-bit environment sets int, long and pointer to 32 bits and generates code that runs on any i386 system. The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and generates code for AMD's x86-64 architecture. For darwin only the -m64 option turns off the -fno-pic and -mdynamic-no-pic options.
What are the possible negative side-effects of compiling a C++ application with x86 settings on a x86_64 platform ?
The most obvious side-effect is that you only have a 32-bit virtual address space with a maximum of 4GB. If your app doesn't use much data, it should be fine.
Unless you are looking for a portable binary, one that will work on 32 bit machines, I wouldn't bother.
Please note, that when you compile a 32 bit target, you need the 32bit versions of any libraries installed as well.
What about the dependencies ? For example, my application uses libpcap library, and if libpcap itself is using other libraries, shoud I also compile these libraries as 32-bit libraries.
If that is the case, the list of all libraries to be compiled as 32-bit may get too long to handle ...
What about the dependencies ? For example, my application uses libpcap library, and if libpcap itself is using other libraries, shoud I also compile these libraries as 32-bit libraries.
If that is the case, the list of all libraries to be compiled as 32-bit may get too long to handle ...
A 32 bit program needs to link to 32 bit versions of the libraries. So in answer to your question, yes.
BTW, you can't really make any mistakes by mixing 32-bit applications with 64-bit libraries. The linker (ld) will make sure, that this doesn't happen. If you try to do that, the linker will complain usually because of mismatching ABI ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.