LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   linux 32 bit compilation on x86_64 with autoconf (http://www.linuxquestions.org/questions/programming-9/linux-32-bit-compilation-on-x86_64-with-autoconf-538042/)

skullmunky 03-16-2007 10: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 12:19 PM

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

skullmunky 03-16-2007 02: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 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!

weibullguy 03-16-2007 03: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
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.


All times are GMT -5. The time now is 05:27 AM.