[CMake] how to compile as 32bit on a 64bit Linux host ?

Yngve Inntjore Levinsen yngve.levinsen at gmail.com
Fri Feb 15 10:26:39 EST 2013


Hello,

On 15/02/13 15:41, Martin Koller wrote:
> I'm just not sure if it is enough to change the compiler flags or if
> there is more to change (paths etc.)
This is why I prefer toolchain files over adding an option inside the
CMakeLists.txt files. On some systems you probably also want to change
the search path for libraries in particular (often /usr/lib32 instead of
/usr/lib), so that the find_package() commands and similar does not find
the incompatible 64 bit libraries.

In our system we both have an option to "force 32 bit" (which basically
just adds -m32 to compile flags), and I have a toolchain file (which
corresponds to my stackoverflow answer). I find the toolchain file to be
more accurate/flexible to get correct setup.

In addition to the three lines you might also want to set paths (I do
not need that on my system for my projects), something along the lines of:

set(CMAKE_FIND_ROOT_PATH  /usr/lib32)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Cheers,
Yngve


More information about the CMake mailing list