LinuxQuestions.org
Review your favorite Linux distribution.
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 07-20-2010, 05:31 AM   #1
flighta
LQ Newbie
 
Registered: Jul 2010
Posts: 2

Rep: Reputation: 0
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.
 
Old 07-20-2010, 05:44 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
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 View Post
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.

Last edited by johnsfine; 07-20-2010 at 05:52 AM.
 
1 members found this post helpful.
Old 07-20-2010, 04:48 PM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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 ?

..

Last edited by knudfl; 07-21-2010 at 08:13 AM.
 
Old 07-20-2010, 08:31 PM   #4
flighta
LQ Newbie
 
Registered: Jul 2010
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
  


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
64bit Centos: need to run 32bit applications. bluepepsi Linux - Server 15 09-21-2009 07:58 AM
How to break the memory limitation on 32bit CentOS Distro? depam Linux - Hardware 10 08-13-2009 08:16 AM
How to compile apache2 to 32bit? rickyforpower Linux - Server 7 12-16-2008 10:23 AM
Cannot load DSO (32bit) in 64bit CentOS jasperphang Linux - Newbie 4 07-27-2006 04:56 AM
how to compile 32bit on amd64 anarhistu Linux - Newbie 1 01-30-2005 04:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:41 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
Open Source Consulting | Domain Registration