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. |
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:
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. |
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 ? .. |
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. |