[CMake] Linking Boost on Linux on 64bit host and 32bit target
Knox, Kent
Kent.Knox at amd.com
Fri Oct 29 17:40:03 EDT 2010
Hi all~
I have a project using Boost that should compile for both 64bit and 32bit on a 64bit host. This works fine for a 64bit target, but I can't get this to work for a 32bit target. I've done a fair share of googling to find this answer, but have not stumbled across anything that helps. In fact, the only flag that I can find to distinguish between 32bit build and 64bit builds only applies to windows with ${CMAKE_CL_64}.
In order to compile for 32bit on a 64bit host, I have a -D parameter called BUILD64. Here is my logic to initialize this var:
if( WIN32 )
set( BUILD64 ${CMAKE_CL_64} )
else()
option( BUILD64 "Build a 64-bit product" OFF )
if( BUILD64 )
message( STATUS "64-bit build" )
endif( )
endif()
The syntax for finding boost is thus:
set( Boost_USE_MULTITHREADED ON )
set( Boost_USE_STATIC_LIBS ON )
set( Boost_DETAILED_FAILURE_MSG ON )
# set( Boost_DEBUG ON )
find_package( Boost 1.33.0 COMPONENTS program_options )
The boost find package module doesn't appear at a glance to distinguish between 64bit and 32bit builds; I don't understand how it is supposed to work. I have a feeling that it is expected that find_library is supposed to distinguish the path behavior, but I don't have it set up right.
When I compile and link for 32bit, I get:
Scanning dependencies of target Foo
[ 72%] Building CXX object client/CMakeFiles/Foo.dir/Foo.cpp.o
[ 81%] Building CXX object client/CMakeFiles/Foo.dir/openCL.cpp.o
[ 90%] Building CXX object client/CMakeFiles/Foo.dir/StatisticalTimer.cpp.o
[100%] Building CXX object client/CMakeFiles/Foo.dir/stdafx.cpp.o
Linking CXX executable Foo
/usr/bin/ld: warning: i386:x86-64 architecture of input file `/usr/local/boost_1_44_0/lib64/libboost_program_options.a(cmdline.o)' is incompatible with i386 output
/usr/bin/ld: warning: i386:x86-64 architecture of input file `/usr/local/boost_1_44_0/lib64/libboost_program_options.a(options_description.o)' is incompatible with i386 output
As you can see, it is looking in lib64 instead of lib. How do I change that behavior?
Thanks for any help,
Kent
More information about the CMake
mailing list