Is it possible to compile a project in 32-bit with cmake
and gcc
on a 64-bit system? It probably is, but how do I do it?
When I tried it the "ignorant" way, without setting any parameters/flags/etc, just setting LD_LIBRARY_PATH
to find the linked libraries in ~/tools/lib
it seems to ignore it and only look in subdirectories named lib64.
For any complex application, I suggest to use an lxc container. lxc containers are 'something in the middle between a chroot on steroids and a full fledged virtual machine'.
For example, here's a way to build 32-bit wine using lxc on an Ubuntu Trusty system:
Here is the wiki page about how to build 32-bit wine on a 64-bit host using lxc.
In short: use the
-m32
flag to compile a 32-bit binary.Also, make sure that you have the 32-bit versions of all required libraries installed (in my case all I needed on Fedora was glibc-devel.i386)
One way is to setup a chroot environment. Debian has a number of tools for that, for example debootstrap
In later versions of CMake, one way to do it on each target is:
set_target_properties(MyTarget PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
I don't know of a way to do it globally.
For C++, you could do:
This works with cmake.