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

Keith Gardner kgardner at zebraimaging.com
Fri Feb 15 10:29:24 EST 2013


What I have done in the past is the -m32 flag to the CMAKE_CXX_FLAGS and all of the search paths were updated automatically.  You just need to add the flag when you CMake for the first time.  I did this on CentOS 5.8 x64 without any problems.

Keith

-----Original Message-----
From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of Yngve Inntjore Levinsen
Sent: Friday, February 15, 2013 9:27 AM
To: cmake at cmake.org
Subject: Re: [CMake] how to compile as 32bit on a 64bit Linux host ?

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
--

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list