Ubuntu – Compile 32 bit on 64 bitsystem


I'm trying to compile a 32 bit version of python on a 64 bit ubuntu system with the following configure command:

CC="gcc -m32" LDFLAGS="-L/lib32 -L/usr/lib32 \ -Lpwd/lib32 -Wl,-rpath,/lib32 \
    -Wl,-rpath,/usr/lib32" \ ./configure --prefix=/opt/pym32

then make, make install. No errors, but it should be something wrong because a "readelf -h python" tells me that python was build as a ELF64 instead.

Best Answer

Use "--build" and "--host".

./configure --help
System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

You need to use

./configure --build=x86_64-pc-linux-gnu --host=i386-pc-linux-gnu

to compile for 32-bit Linux in a 64-bit Linux system. You still need to add the other ./configure options.