LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-25-2010, 04:39 AM   #1
aryan1
Member
 
Registered: Jul 2009
Posts: 50

Rep: Reputation: 16
Question 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.

Last edited by aryan1; 01-25-2010 at 04:41 AM.
 
Old 01-25-2010, 12:42 PM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
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.
 
Old 01-25-2010, 01:05 PM   #3
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Quote:
Originally Posted by aryan1 View Post
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.
 
Old 01-26-2010, 01:32 AM   #4
Borax_Man
Member
 
Registered: Jan 2009
Posts: 31

Rep: Reputation: 16
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.
 
Old 01-26-2010, 03:15 AM   #5
aryan1
Member
 
Registered: Jul 2009
Posts: 50

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Borax_Man View Post
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 ...
 
Old 01-26-2010, 03:18 AM   #6
Borax_Man
Member
 
Registered: Jan 2009
Posts: 31

Rep: Reputation: 16
Quote:
Originally Posted by aryan1 View Post
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.
 
Old 01-26-2010, 05:47 AM   #7
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
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 -
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling x86 apps on an x86-46 system. arfon Linux - Software 2 10-06-2008 02:13 AM
x86 or x86_64? Necromuru Linux - Newbie 2 11-12-2007 08:30 AM
x86 vs. x86_64 andy.l SUSE / openSUSE 2 10-05-2007 02:18 PM
x86 vs x86_64 kotnik Linux - General 3 10-04-2007 11:58 AM
X86 or X86_64? daihard Linux - Software 10 09-15-2005 12:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration