LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-16-2007, 11:55 AM   #1
skullmunky
Member
 
Registered: Aug 2003
Posts: 42

Rep: Reputation: 15
linux 32 bit compilation on x86_64 with autoconf


after loads of googling i can't find a simple answer, so maybe someone here knows:

i'm on an AMD64 suse. i'm trying to compile a library that will later be used from a 32 bit application, so i need to compile the library as 32bit.

it's set up with autoconf (e.g. ./configure, make, make install). how exactly do i tell configure to build for an ix86 (i386 or i586 or i686 etc) platform instead of x86_64? should something like this work?

./configure --build=i586

what's the difference between --build, --host, and the other flags in configure?

i know you can do this by setting the -m32 flag for compiling and linking (e.g. CFLAGS=-m32 LFLAGS=-m32 CXXFLAGS=-m32) but this seems unnecessarily complicated.
 
Old 03-16-2007, 01:19 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,753
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
Here is a description of the --host, --build, and --target flags.

To get the AMD64 triplet
Code:
export BUILD="$(echo $MACHTYPE | sed "s/$(echo $MACHTYPE | cut -d- -f2)/cross/")"
Run the same on the target machine if you can to get it's triplet. If you can't do that you should be OK using (unless you're building for a MIPS, PowerPC, Sparc, etc.):
  • 486 Compatibles --> i486-pc-linux-gnu
  • Pentium, K6, and 586 Compatibles --> i586-pc-linux-gnu
  • Pentium II, Pentium III, Pentium 4 --> i686-pc-linux-gnu
  • Athlon --> i686-pc-linux-gnu

Then
Code:
./configure --build=$BUILD --host=$TARGET --target=$TARGET
 
Old 03-16-2007, 03:58 PM   #3
skullmunky
Member
 
Registered: Aug 2003
Posts: 42

Original Poster
Rep: Reputation: 15
seems to be almost working but not quite. here's what's happened:

i did ./configure --build=i586

(before i saw your reply - next will try it with build, host, and target, all of them )

everything compiled, linked, installed ok.

specifically, i'm building the ODE open dynamics engine. i get libode.so and libode.a in /usr/local/lib, which is what's supposed to happen.

next, i try to compile a little test program to use libode:

g++ -m32 -c odetest.c
g++ -m32 -o odetest -L/usr/X11R6/lib -lX11 -lglut -lGL -lXi -lXmu -lode -lode

/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/local/lib/libode.so when searching for -lode

so the compile/link is correctly targeting 32bit, and looking in the right place (/usr/local/lib, and not /usr/local/lib64), but libode.so is still wrong.

so then:

ldd /usr/local/lib/libode.so
libstdc++.so.5 => /usr/lib64/libstdc++.so.5 (0x00002aaaaac3f000)
libpthread.so.0 => /lib64/tls/libpthread.so.0 (0x00002aaaaae1c000)
libm.so.6 => /lib64/tls/libm.so.6 (0x00002aaaaaf31000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002aaaab088000)
libc.so.6 => /lib64/tls/libc.so.6 (0x00002aaaab194000)
/lib64/ld-linux-x86-64.so.2 (0x0000555555555000)

nuts!
 
Old 03-16-2007, 04:57 PM   #4
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,753
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
First, are you building the library for use on YOUR AMD64 machine just for use with 32-bit applications?

Your test program is NOT building correctly
Quote:
skipping incompatible /usr/local/lib/libode.so when searching for -lode
It looks like you are building a 64-bit libode and then trying to build a 32-bit application to use it. It is installed in /usr/local/lib because that's the default location. You would pass the --libdir=/usr/local/lib64 flag to the configure script for 64-bit libraries.

Rebuild libode like this and then try your test program.
Code:
export BUILD32="-m32 -O2 -pipe"
export PKG_CONFIG_PATH32="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/X11R6/lib/pkgconfig"
CC="gcc ${BUILD32}" PKG_CONFIG_PATH="${PKG_CONFIG_PATH32}" ./configure
make
su -c 'make install'
You may or may not need the PKG_CONFIG_STUFF for libode depending on whether or not it looks for *.pc files. Add or subtract from the BUILD32 variable as you wish, but the -m32 MUST be there.

Last edited by weibullguy; 03-16-2007 at 06:30 PM.
 
  


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
*** YOU'RE USING autoconf (GNU Autoconf) 2.60. KDE requires autoconf 2.52, 2.53 or 2. arubin Slackware 6 09-24-2008 04:31 AM
AMD-64 processor with x86_64 or 32-bit kernel? oskar General 29 07-18-2007 08:01 PM
32-bit Firefox on x86_64 (FC5)... sancho Fedora 20 10-24-2006 06:42 AM
32 bit mplayer on x86_64 ciopi Linux - Software 2 11-14-2005 11:10 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 02:59 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