-   Programming (
-   -   linux 32 bit compilation on x86_64 with autoconf (

skullmunky 03-16-2007 11:55 AM

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.

weibullguy 03-16-2007 01:19 PM

Here is a description of the --host, --build, and --target flags.

To get the AMD64 triplet

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


./configure --build=$BUILD --host=$TARGET --target=$TARGET

skullmunky 03-16-2007 03:58 PM

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 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/ 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 is still wrong.

so then:

ldd /usr/local/lib/ => /usr/lib64/ (0x00002aaaaac3f000) => /lib64/tls/ (0x00002aaaaae1c000) => /lib64/tls/ (0x00002aaaaaf31000) => /lib64/ (0x00002aaaab088000) => /lib64/tls/ (0x00002aaaab194000)
/lib64/ (0x0000555555555000)


weibullguy 03-16-2007 04:57 PM

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

skipping incompatible /usr/local/lib/ 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.

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

All times are GMT -5. The time now is 10:39 PM.