[CMake] Configure 32 bit build in 64 bit environment from cli
Nicola Mori
nicolamori at aol.com
Wed Mar 27 05:37:12 EDT 2013
Hello, for my project I'd like to be able to configure a 32 bit build
with GCC in a 64 bit Linux environment by setting variables from command
line interface. As far as I understand of CMake, this can be
accomplished by setting CMAKE_CXX_FLAGS and CMAKE_SHARED_LINKER_FLAGS to
"-m32" (my project consists only of a library). So I configure with:
cmake -DCMAKE_CXX_FLAGS=-m32 -DCMAKE_SHARED_LINKER_FLAGS=-m32 /path/to/code
and indeed the cached variables reflect my settings:
$ cmake -i /path/to/code
Variable Name: CMAKE_CXX_FLAGS
Description: Flags used by the compiler during all build types.
Current Value: -m32
Variable Name: CMAKE_SHARED_LINKER_FLAGS
Description: Flags used by the linker during the creation of dll's.
Current Value: -m32
So everything seems fine, and then I launch make. I immediately get this
error message:
/usr/bin/ld: i386:x86-64 architecture of input file
`CMakeFiles/GGSNameDecoder.dir/GGSNameDecoder.cpp.o' is incompatible
with i386 output
So it seems that the linker is trying to create a 32 bit library using a
64 bit object file. Indeed, the object file is 64 bit:
$ file src/CMakeFiles/GGSNameDecoder.dir/GGSNameDecoder.cpp.o
src/CMakeFiles/GGSNameDecoder.dir/GGSNameDecoder.cpp.o: ELF 64-bit LSB
relocatable, x86-64, version 1 (SYSV), not stripped
So I would say that the setting of CMAKE_CXX_FLAGS is ignored while
CMAKE_SHARED_LINKER_FLAGS is correctly accounted for. I tried to set
also CMAKE_C_FLAGS to -m32 without success, anyway my code is C++.
Interestingly, if I hard-code the -m32 into my CMakeLists.txt like this:
set(CMAKE_CXX_FLAGS "-m32")
then the 32 bit build works smoothly.
I get this behavior both with CMake 2.8.7 and 2.8.10. I don't know if I
am missing something, if it is a bug in CMake or in my project, or if it
is the intended behavior. I only know that I would need some help to get
through it, thanks!
More information about the CMake
mailing list