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 |
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.
|
$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 |
Quote:
|
Quote:
|
Quote:
Code:
ld -m elf_i386 -o foo foo.o |
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 |
Quote:
|
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 |
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 |
Hi
I have the same problem : I have a Xeon 64bit processor, Fedora 8 x86_64 : Quote:
Quote:
Code:
#include <stdio.h> When I compile this on my 64bit machine with the option -m32: Quote:
Quote:
Here my gcc version : 64bit : Quote:
Quote:
|
Quote:
On your 64-bit machine, try something like this: Code:
gcc -m32 -march=i686 main.c |
Sorry for the late reply.
I tried the option -march=i686 : nothing changed ... :( (I tried also i386 i586) Quote:
|
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 |
Quote:
|
Quote:
Maybe some expert will answer (I'm definitely not). But meanwhile, here is the way I would attack the problem if I needed to do what you're trying: Quote:
Check with your package manager to find out which 32-bit package contained that file. Go to the ftp site for your distribution and download (not install) the 64-bit build of that same package. Open the package with ark (instead of the package manager) to extract the .gz file that contains the package data. Open that .gz file and see what directories contain .so, .a or .o files. Make "64" versions of those same directories (for example, you will find libm.so goes in /usr/lib, so make a corresponding /usr/lib64 directory). Drag each of those files from the .gz to the "64" directory you created for it. Figure out the right g++ switches or environment variables to make it look there. Retry the build. I'm sure experts know a cleaner way to automate some of the above steps. But the above is the way I know. Quote:
|
To samitpmc # 14 : lm ~ libm.so ... please see this
http://www.linuxquestions.org/questi...mpiler-656359/ Regards |
All times are GMT -5. The time now is 10:56 AM. |