LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 12-13-2007, 11:02 AM   #1
uttam_h
LQ Newbie
 
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28

Rep: Reputation: 15
compiling 32 bit application on 64 bit linux(x86_64)


hi all,
i have a 64 bit linux machine.

$uname -a
Linux SVRDELLD30 2.6.9-42.ELsmp #1 SMP Tue Aug 15 10:35:26 BST 2006 x86_64 x86_64 x86_64 GNU/Linux

here by default gcc creates 64 bit executable. but for some reason i want to create 32bit executable.

first i want to create 32 bit object files(.o files) and then i want to link those object files.

Please suggest me suitable gcc options.

Thanks and Regards,
uttam hoode
 
Old 12-13-2007, 11:47 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,755
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
If you have a toolchain that supports multilib, then you would pass the -m32 flag to the compiler to generate 32-bit, i386 compatible code. If you don't have a toolchain with multilib support, you can't create 32-bit apps or libs on an x86_64 system.
 
Old 12-13-2007, 11:58 AM   #3
uttam_h
LQ Newbie
 
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28

Original Poster
Rep: Reputation: 15
$gcc -print-multi-lib
.;
32;@m32


$gcc -print-multi-os-directory -m32; gcc -print-multi-os-directory -m64; gcc -print-multi-os-directory
../lib
../lib64
../lib64

when i gave -m32 option gcc created 32 bit object files....

$file Logger.o
Logger.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped

but im getting error while linking .o files.

Thanks and Regards,
uttam hoode

Last edited by uttam_h; 12-13-2007 at 12:07 PM.
 
Old 12-13-2007, 01:28 PM   #4
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by uttam_h View Post
but im getting error while linking .o files.
Try passing "-m32" to the linker command.
 
Old 12-13-2007, 03:51 PM   #5
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,755
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
Quote:
Originally Posted by uttam_h View Post
but im getting error while linking .o files.
The actual error might be more helpful.
 
Old 12-13-2007, 06:11 PM   #6
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Quote:
Originally Posted by David1357 View Post
Try passing "-m32" to the linker command.
If you are using GNU ld, and it complains about incompatible objects, try something like this instead:
Code:
ld -m elf_i386 -o foo foo.o
 
Old 12-13-2007, 10:51 PM   #7
uttam_h
LQ Newbie
 
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28

Original Poster
Rep: Reputation: 15
hi weibullguy,
im getting following errors while linking(using gcc)


/usr/bin/ld: warning: i386 architecture of input file `global.o' is incompatible with i386 output
/usr/bin/ld: warning: i386 architecture of input file `Logger.o' is incompatible with i386 output
/usr/bin/ld: warning: i386 architecture of input file `tap311.o' is incompatible with i386 output

when i used ld with -m elf_i386 (as suggest by osor) i got follwing errors but executable is created

ld: warning: cannot find entry symbol _start; defaulting to 0000000008048a80


and executable is throwing this error


-bash: ./myapp: /usr/lib/libc.so.1: bad ELF interpreter: No such file or directory


Thanks and Regards,
uttam hoode

Last edited by uttam_h; 12-13-2007 at 10:54 PM.
 
Old 12-14-2007, 08:47 AM   #8
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by uttam_h View Post
when i used ld with -m elf_i386 (as suggest by osor) i got follwing errors but executable is created

ld: warning: cannot find entry symbol _start; defaulting to 0000000008048a80
Try adding "-lcrt0" to make sure you are getting the C startup code.
 
Old 12-14-2007, 11:09 AM   #9
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
An alternative to all these shenanigans is to use gcc as your linker frontend. It will automatically pick the correct options for you:
Code:
gcc -m32 -o output tap311.o Logger.o global.o
 
Old 12-16-2007, 08:08 AM   #10
uttam_h
LQ Newbie
 
Registered: Sep 2002
Location: mangalore,india
Distribution: redhat
Posts: 28

Original Poster
Rep: Reputation: 15
hi all,
created object files and i am able to link them using -m32....now i have a 32bit executable on x86_64 machine...but when i tried to execute i am getting segmentation fault error.

(i copied 32bit executable from i386 machine to x86_64 machine and it s working fine. both i386 and x86_64 machines have same version of gcc and glibc)

Thanks and Regards,
uttam hoode

Last edited by uttam_h; 12-16-2007 at 08:09 AM.
 
Old 12-21-2007, 08:11 AM   #11
mhtrinh
LQ Newbie
 
Registered: Jan 2006
Location: Avignon, France
Posts: 16

Rep: Reputation: 0
Hi

I have the same problem :
I have a Xeon 64bit processor, Fedora 8 x86_64 :
Quote:
Linux sbtn155**** 2.6.23.1-49.fc8 #1 SMP Thu Nov 8 22:14:09 EST 2007 x86_64 x86_64 x86_64 GNU/Linux
And another machine with a 32bit processor, with Fedora core 5 :
Quote:
Linux sbtn151**** 2.6.15-1.2054_FC5 #1 Tue Mar 14 15:48:33 EST 2006 i686 i686 i386 GNU/Linux
I have a simple C code: main.c:
Code:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    printf("Hello world\n");
    return 1;
}
When I compile this on my 32bit machine, the executable run on both machine.

When I compile this on my 64bit machine with the option -m32:
Quote:
gcc -m32 main.c
It run only on the 64bit machine. On the other on, I got this error :
Quote:
$ ./a.out
Floating exception
With google, it seems that am the only human with this problem (X_X)

Here my gcc version :
64bit :
Quote:
$ gcc --version
gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-33)
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.
32bit :
Quote:
$ gcc --version
gcc (GCC) 4.1.0 20060304 (Red Hat 4.1.0-3)
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.
 
Old 01-01-2008, 02:23 PM   #12
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
Quote:
Originally Posted by mhtrinh View Post
When I compile this on my 32bit machine, the executable run on both machine.

When I compile this on my 64bit machine with the option -m32:


It run only on the 64bit machine. On the other on, I got this error :


With google, it seems that am the only human with this problem (X_X)
Have you considered that the architecture is being used during compilation and/or linking? I.e., there may be architecture-specific optimizations available to your Xeon over your 32-bit machine apart from its 64-bittedness.

On your 64-bit machine, try something like this:
Code:
gcc -m32 -march=i686 main.c
 
1 members found this post helpful.
Old 01-07-2008, 03:15 AM   #13
mhtrinh
LQ Newbie
 
Registered: Jan 2006
Location: Avignon, France
Posts: 16

Rep: Reputation: 0
Sorry for the late reply.

I tried the option -march=i686 : nothing changed ... (I tried also i386 i586)

Quote:
Have you considered that the architecture is being used during compilation and/or linking? I.e., there may be architecture-specific optimizations available to your Xeon over your 32-bit machine apart from its 64-bittedness.
... I don't know ...
 
Old 07-17-2008, 08:51 AM   #14
samitpmc
LQ Newbie
 
Registered: Jul 2008
Posts: 8

Rep: Reputation: 0
Hello

My problem is just opposite. I want to build x64 application from my 32 bit ubuntu machine with gcc 4.1.2 installed.

I have test.cpp

#include <iostream>

int main()
{
cout<<"hello world"
return 0;
}

now compiling this code using
g++ -m64 test.cppI get error.

/usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linuxgnu/4.1.2/../../../libm.so when searched for lm

/usr/bin/ld: cannot find lm.

waiting for your suggestion.

Regards
Amit
 
Old 07-19-2008, 04:28 AM   #15
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,320

Rep: Reputation: 62
Quote:
Originally Posted by uttam_h View Post
hi all,
created object files and i am able to link them using -m32....now i have a 32bit executable on x86_64 machine...but when i tried to execute i am getting segmentation fault error.

(i copied 32bit executable from i386 machine to x86_64 machine and it s working fine. both i386 and x86_64 machines have same version of gcc and glibc)

Thanks and Regards,
uttam hoode
YOU CANT RUN A 32 BIT EXE ON A 64BIT MACHINE!!! WHAT KIND OF PERSON KNOWS THE TERMS "32-BIT", "64-BIT", PROGRAMS, BUT DOESNT KNOW THAT??!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 64 bit kernel in 32 bit linux MadnessASAP Linux - Hardware 6 05-04-2009 12:47 PM
linux 32 bit compilation on x86_64 with autoconf skullmunky Programming 3 03-16-2007 04:57 PM
compiling in 32-bit mode on 64-bit Linux germanymontrealexpat Linux - Software 2 05-26-2006 08:39 AM
Compiling 32-bit binary in a 64-bit environment Kaj Linux - Software 1 12-13-2004 10:43 AM
Use 32 bit and x86_64 Linux on same system? jfried Linux - Newbie 1 11-16-2004 12:05 AM


All times are GMT -5. The time now is 03:11 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration