60

I'm using a 64bit system but want a set of 32bit binaries. What options must I pass to a configure script to generate a 32bit/x86 makefile?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Jack Nock
  • 14,703
  • 5
  • 22
  • 18
  • Plus one. I'm trying to build Git for Solaris. `uname -m` returns `i86pc`. All but one of the 10 or so dependent libraries misdetected the platform. Only OpenSSL correctly identified it as x86_64. – jww Mar 29 '17 at 06:50

5 Answers5

74

Passing the following argument to configure script allowed me to build the 32bit library on 64bit Linux

./configure --build=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32
fuzzyTew
  • 3,511
  • 29
  • 24
Jack Nock
  • 14,703
  • 5
  • 22
  • 18
  • Doesn't work for me :( Please help me at http://stackoverflow.com/questions/13780319/cant-build-32bit-wine-on-64bit-linux – m93a Dec 08 '12 at 18:11
  • 4
    It didn't work for me when trying to build a library. It gave me the message `configure: error: C++ compiler cannot create executables`. – Craig McQueen Jul 17 '13 at 22:36
  • 2
    This answer is incomplete, which is why sometimes you can get the "compiler cannot create executables" error. See my answer in this same thread – volpato Jul 19 '13 at 14:04
54

Jack's answer is incomplete.

You need compiler/libc support for 32-bit compilation. In some distros like Ubuntu, what you need to do is install packages gcc-multilib and/or g++-multilib:

sudo apt-get install gcc-multilib g++-multilib

Then you can call configure as you said, specifyiong a 32-bit host and passing 32-bit compilation flags:

./configure --host=i686-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"

If you do not have multilib installed, you will get an error like configure: error: C compiler cannot create executables when passing the -m32 flag.

volpato
  • 1,262
  • 17
  • 21
  • 3
    Some programs compile 32-bit on amd64 by default (eg. wine,) possibly in addition to 64-bit and should be able to find multilib if installed. Doesn't seem to be the case for OP. Also, Jack was right about one thing - it should be `--build`, not `--host`. `--host` should be used if and only if you are building a compiler. It still works because there is plenty of people who don't RTFM and write scripts that use `--host` instead of `--build`, and the autotools people have broken enough things already. – Jonathan Baldwin Sep 23 '13 at 21:17
  • the *-multilib packages doesn't exist anymore in Debian stable. – Braiam Mar 22 '14 at 17:27
  • I still see `g++-multilib` in Debian Stretch. As well as that, you will need to enable 32-bit runtime libraries, as documented at https://wiki.debian.org/Multiarch/HOWTO. The commands at the bottom of that page `dpkg --add-architecture i386; apt-get install libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386` are a good starting point. You can install extra libraries as needed now, for example to build something that requires SSL, you can `apt-get install libssl-dev:i386`. – Michael Firth Aug 29 '19 at 18:10
  • @JonathanBaldwin `./configure --help` says (for a script generated by autoconf): `System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD]` – real-or-random Mar 03 '21 at 23:36
8

I had better success by setting a custom compiler instead. This way all the configure tests, even the ones using custom CFLAGS, worked correctly:

./configure CC="gcc -m32" CXX="g++ -m32"

You still need 32-bit versions of all the libraries the application uses of course, so any errors about missing libraries are referring to the 32-bit ones.

Malvineous
  • 25,144
  • 16
  • 116
  • 151
4

Assuming gcc/g++:

CPPFLAGS=-m32 ./configure ...
R Samuel Klatchko
  • 74,869
  • 16
  • 134
  • 187
  • 1
    Thanks for the answer. The configure script still sets the build system type and host system type to x86_64-unknown-linux-gnu. Do you know how to override these? – Jack Nock Jul 16 '10 at 11:14
1

An alternative way to the things described above would be (if you have) to use a dedicated x86 compiler. The configure line would then be like this (I named the x86-tools after the pattern "<toolname>-x86"):

CC="/path/to/c/compiler/gcc-x86" CXX="path/to/cpp/compiler/g++-x86" LD="path/to/linker/ld-x86" ./configure
Haringat
  • 11
  • 1