LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   compiling a C++ program using g++ with x86 settings on x86_64 (https://www.linuxquestions.org/questions/programming-9/compiling-a-c-program-using-g-with-x86-settings-on-x86_64-a-784552/)

aryan1 01-25-2010 04:39 AM

compiling a C++ program using g++ with x86 settings on x86_64
 
Hi All,

How can I compile a C++ application using g++ with x86 platform settings on a x86_64 machine ?

What are the possible negative side-effects of compiling a C++ application with x86 settings on a x86_64 platform ?

I am using 64-bit Ubuntu 9.10.

Thanks.

a4z 01-25-2010 12:42 PM

from man gcc:

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.

ForzaItalia2006 01-25-2010 01:05 PM

Quote:

Originally Posted by aryan1 (Post 3839572)
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.

Borax_Man 01-26-2010 01:32 AM

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.

aryan1 01-26-2010 03:15 AM

Quote:

Originally Posted by Borax_Man (Post 3840640)
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 ...

Borax_Man 01-26-2010 03:18 AM

Quote:

Originally Posted by aryan1 (Post 3840694)
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.

ForzaItalia2006 01-26-2010 05:47 AM

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 ...

- Andi -


All times are GMT -5. The time now is 04:38 PM.