General way of building 32bit projects on 64bit system

compilinggccmakemultiarch

I have a project that is supposed to run on all following platforms:

  • Win x86
  • Win x64
  • Linux (Debian) x86
  • Linux (Debian) x64

I'm finish with windows and Linux x64 compiled although I'm not sure it works. There's one platform missing and that's Linux x86. I have a makefile which doesn't care about x64/x32. I need to add a 32bit configuration. I learned that I can do this with make:

make configuration CFLAGS=-m32

But I'm not so sure it does actual 32bit build – when I used that command, no compilation occurred1 and the program skipped right to the linking phase, where it indeed complained about incompatible libraries2:

/usr/bin/ld: cannot find -lboost_system
/usr/bin/ld: skipping incompatible /usr/lib//liblog4cplus.so when searching for -llog4cplus
/usr/bin/ld: skipping incompatible /usr/lib//liblog4cplus.a when searching for -llog4cplus
/usr/bin/ld: skipping incompatible /usr/local/lib/liblog4cplus.so when searching for -llog4cplus
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../liblog4cplus.so when searching for -llog4cplus
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../liblog4cplus.a when searching for -llog4cplus
/usr/bin/ld: skipping incompatible //usr/local/lib/liblog4cplus.so when searching for -llog4cplus
/usr/bin/ld: skipping incompatible //usr/lib/liblog4cplus.so when searching for -llog4cplus
/usr/bin/ld: skipping incompatible //usr/lib/liblog4cplus.a when searching for -llog4cplus
/usr/bin/ld: cannot find -llog4cplus
/usr/bin/ld: skipping incompatible /usr/local/ssl/lib//libcrypto.a when searching for -lcrypto
/usr/bin/ld: cannot find -lcrypto

This raises about two questions on people who are used to develop multi-architecture programs:

  1. How should I manage libraries? And do I have to manually build them all?
  2. How to properly make the makefile? I suppose the 32bit version and 64bit version should build in different locations…

Note 1: I noticed that this happens because I didn't make clean. Still, the 64bit and 32bit shouldn't share folders.
Note 2: This includes -lstdc++ – the C++ standard library. This means I don't even have that one.

Best Answer

You need to set up your build scripts so that object files for different architectures are written into different directories. There will naturally be no conflicts between Windows objects and Unix objects because they use different file names (*.obj and *.exe vs. *.o and *), but Unix systems use the same file names.

Alternatively, unpack the sources in different directories for each build.

Regarding the libraries, you'll need to install 32-bit (…:i386) development packages alongside the native 64-bit ones. Alternatively, set up a 32-bit installation in a chroot, which uses a few GB of disk space but is very low maintenance and is the easiest way of reliably producing packages for other distributions than the one you're running.

Related Question