Find the answer to your Linux question:
Results 1 to 10 of 10
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++ ...
  1. #1
    Just Joined!
    Join Date
    Nov 2009
    Posts
    43

    Question compiling a C++ program using g++ with x86 settings

    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.

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    I think -m32 will do it

    g++ filename -m32 -o filename
    Make mine Arch Linux

  3. #3
    Just Joined!
    Join Date
    Nov 2009
    Posts
    43
    Quote Originally Posted by gerard4143 View Post
    I think -m32 will do it

    g++ filename -m32 -o filename
    I already tried that.

    However, when it comes to linking, gcc came across the 32-bit versions of the libraries where it expected the 64-bit ones.

    Should I make -m32 a linker option as well ?

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by aryan_ View Post
    I already tried that.

    However, when it comes to linking, gcc came across the 32-bit versions of the libraries where it expected the 64-bit ones.

    Should I make -m32 a linker option as well ?
    Well, with the -m32 option (or -m32-bit option) the compiler should pass the 32-bit info to the linker, so it should link with the 32-bit versions. In fact, you are basically building for a 32-bit environment, so all required libraries should be available in their 32-bit version, otherwise you have a 32-bit program that will only run on a 64-bit machine...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Nov 2009
    Posts
    43
    Quote Originally Posted by Rubberman View Post
    Well, with the -m32 option (or -m32-bit option) the compiler should pass the 32-bit info to the linker, so it should link with the 32-bit versions.
    I added -m32 to the linker options as well, and it successfully linked against the 32-bit library. Otherwise, it was complaining about the "incompatible" library, and aborting the linking process. So, somehow, compiler did not pass 32-bit info to the linker before.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Were you using gcc/g++ to do the linkage, or directly going to ln?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Just Joined!
    Join Date
    Nov 2009
    Posts
    43
    Quote Originally Posted by Rubberman View Post
    Were you using gcc/g++ to do the linkage, or directly going to ln?
    I was using gcc.

  8. #8
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Oops, I meant ld not ln. So, you probably needed to add the -Wl,-m32 option to pass to the linker, correct?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #9
    Just Joined!
    Join Date
    Nov 2009
    Posts
    43
    Quote Originally Posted by Rubberman View Post
    Oops, I meant ld not ln. So, you probably needed to add the -Wl,-m32 option to pass to the linker, correct?
    Yes. I added -m32 to linker options.

  10. #10
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Ok. Then if I were you I'd post this issue as a possible bug to the gcc / gnu / FSF web site's bug page. I'd think, personally, that the -w32 option to the compiler should be passed as necessary to the linker.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...