LinuxQuestions.org
Visit Jeremy's Blog.
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 06-10-2008, 07:03 PM   #1
linuxmthomson
LQ Newbie
 
Registered: Jun 2008
Posts: 4

Rep: Reputation: 0
Compiling 32bit C++ on 64bit Linux


Hi all,

I am running Linux Red Hat 5 64bit OS and I am trying to work out how to compile 32 bit c++ apps on this 64 bit OS.

I have a simple helloworld app that compiles and runs with default compilation :


g++ test.cpp -> produces a.out that runs without issue

Now I am trying to get it to build in 32bit mode using -m32
and I get the following error:

g++ -m32 test.cpp
In file included from /usr/include/features.h:352,
from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/x86_64-redhat-linux/bits/os_defines.h:39,
from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/x86_64-redhat-linux/bits/c++config.h:39,
from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iostream:43,
from test.cpp:1:
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory

I think it may be a problem because it looks like there may be no 32 bit C++ libs / headers installed

The only directory under /usr/lib/gcc is x86_64-redhat-linux

Any help would be greatly appreciated!
 
Old 06-11-2008, 06:46 AM   #2
student04
Member
 
Registered: Jan 2004
Location: USA
Distribution: macOS, OpenBSD
Posts: 669

Rep: Reputation: 34
I know for a fact that various operating systems (not just talking about linux ones) have either only support for the 64-bit environment, support both 64/32-bit, or for 32-bit only. Ubuntu, to my latest knowledge, has a 64-bit version but which cannot run 32-bit binaries. Gentoo's 64-bit versions indeed have support for the 32-bit libraries (my install has /usr/lib32 and /usr/lib64 for each group).

I just compiled and ran this file on my gentoo box:
Code:
[alex@suicide temp]$ gcc --version
gcc (GCC) 4.1.2 (Gentoo 4.1.2 p1.1)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[alex@computer temp]$ cat test.c
#include <stdio.h>
int main() {
        printf( "works\n" );
}
[alex@computer temp]$ gcc test.c -o test64
[alex@computer temp]$ gcc -m32 test.c -o test32
[alex@computer temp]$ file test64
test64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), not stripped
[alex@computer temp]$ file test32
test32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), not stripped
[alex@computer temp]$ ./test64
works
[alex@computer temp]$ ./test32
works
Try to see if you can do this with a simple C file like I did (they use fewer headers). If that doesn't work, I'd look to see if you can install packages from the repository that are the 32-bit libraries.

Oh, and welcome to LQ!

Last edited by student04; 06-11-2008 at 06:48 AM.
 
Old 06-11-2008, 05:46 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, Linuxmthomson -

You're absolutely on the right track:

a) You've got G++ installed, and confirmed that it can successfully build 64-bit .exe's

b) You know about, and tried, "-m32" to try building a 32-bit .exe.

So far, so good. I think you'll be home free if you just installed the 32-bit dev tools (along with the 64-bit tools you've already got):

Quote:
EXAMPLE:
sudo apt-get install libc6-dev-i386
You should be able to install and use both the 32- and 64-bit dev tools - just make sure they're both the *same* version of GCC.

'Hope that helps .. PSM
 
Old 06-11-2008, 06:05 PM   #4
linuxmthomson
LQ Newbie
 
Registered: Jun 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks guys.

Yes, using Yum I managed to update most of the dependant libs ( using a generic yum update ) then ran a :

yum install glibc-devel

and that installed the correct lib.

I can now compile both 32 and 64 bit apps.

Thanks for your help
 
  


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
32bit and 64bit linux file size limitation Swakoo Linux - General 2 09-05-2007 07:21 AM
32bit windows vmware and 64bit linux pandah General 1 07-17-2007 03:24 PM
Info re 64bit vs. 32bit Linux gmcauley Linux - General 8 04-18-2007 06:41 AM
Compiling MPlayer 32bit on Fedora 4 64bit mwales Linux - Software 2 08-28-2006 05:59 AM
can 64bit processor run both 64bit and 32bit computers? DJOtaku Linux - General 4 09-08-2005 08:14 PM

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

All times are GMT -5. The time now is 02:32 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