LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to compile 32bit on CentOS 5 64bin (https://www.linuxquestions.org/questions/linux-software-2/how-to-compile-32bit-on-centos-5-64bin-820959/)

flighta 07-20-2010 05:31 AM

how to compile 32bit on CentOS 5 64bin
 
first I use gcc to compile it with -m32.
/usr/bin/gcc -g -w -m32 -fPIC -c -x c -shared -o -I. -I/prog/lib test.c
then I try to link it use
/usr/bin/ld -shared -o test.so test.o

but here I get the wrong report
/usr/bin/ld: warning: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output
test.o: In function `dfm_test':
/misc/test.c:238: undefined reference to `_GLOBAL_OFFSET_TABLE_'
/misc/test.c:286: undefined reference to `odb__call_do'

But if compile it without -m32 then the link is OK, but I need the 32bit action.

johnsfine 07-20-2010 05:44 AM

I normally use gcc for both compiling and linking, so I don't need to learn the ld versions of any options that need to be given to both. But at the moment I don't recall the gcc option syntax for selecting output as a .so

I think the ld option -m elf_i386 corresponds to the gcc option -m32 so try

/usr/bin/ld -m elf_i386 -shared -o test.so test.o

Quote:

Originally Posted by flighta (Post 4039304)
if compile it without -m32 then the link is OK

Does that mean your .c file is completely self contained (doesn't use any library functions)? Or does it mean ld is finding the right libraries by default? If the latter, I wonder if that also is configured only for 64 bit on your system.

So in addition to getting ld to write the correct format using -m elf_i386, you might also need additional options to get it to read the right libraries.

I don't use ld directly much, and when I do it doesn't include the right libraries by default, so I need to explicitly include the libraries. I'm used to using the gcc command for linking and gcc is properly configured to include the right default libraries when linking.

knudfl 07-20-2010 04:48 PM

CentOS 5.x -64 Bit : i686 packages are available for :
'binutils-devel' (ld), glibc, glibc-devel, etc.

May be they are required, when you build for i686 ?

..

flighta 07-20-2010 08:31 PM

Thank you!
/usr/bin/ld -m elf_i386 -shared -o test.so test.o
can make it run success.

Some of lib is self define, some of them are from system.

I will to use gcc for link also, by the way, what is the different between them.


All times are GMT -5. The time now is 10:43 AM.