[CMake] Linking Boost on Linux on 64bit host and 32bit target

Knox, Kent Kent.Knox at amd.com
Wed Nov 3 18:57:10 EDT 2010


Hello all~

I'm going to follow up on my email from last week with more information.  I don't believe that find_package( Boost ) is behaving properly in my case, and I need help with either a proper solution or a workaround.

I'm using Cmake 2.8.2, on a 64bit Ubuntu linux host, trying to compile a 32bit package with boost.  

I have manually downloaded and compiled boost 1.44 into my home directory, ~/sdk/boost_1_44_0.  The system also has boost 1.40 installed using a package manager into /usr/lib.

I manually invoke cmake with this command line:
~/bin/cmake-2.8.2-Linux-i386/bin/cmake -G "Unix Makefiles" -D BOOST_ROOT=~/sdk/boost_1_44_0 -D BOOST_LIBRARYDIR=~/sdk/boost_1_44_0/stage/lib -D ATISTREAMSDKROOT=/usr/src/ati/ati-stream-sdk-v2.2-lnx64 -D BUILD64=OFF -D CMAKE_BUILD_TYPE=Debug  ../../code

Notice that I explicitly set BOOST_ROOT and BOOST_LIBRARYDIR, and the debug output seems to confirm my settings.

This is my output when I run 'make VERBOSE=1':

-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:373 ] Boost not in cache
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:376 ] _boost_TEST_VERSIONS = 1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:378 ] Boost_USE_MULTITHREADED = ON
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:380 ] Boost_USE_STATIC_LIBS = ON
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:439 ] Declared as CMake or Environmental Variables:
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:441 ]   BOOST_ROOT = /home/kknox/sdk/boost_1_44_0
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:443 ]   BOOST_INCLUDEDIR =
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:445 ]   BOOST_LIBRARYDIR = /home/kknox/sdk/boost_1_44_0/stage/lib
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:447 ] _boost_TEST_VERSIONS = 1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:496 ] Include debugging info:
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:498 ]   _boost_INCLUDE_SEARCH_DIRS = /home/kknox/sdk/boost_1_44_0/include;/home/kknox/sdk/boost_1_44_0;C:/boost/include;C:/boost;/boost/include;/boost;/sw/local/include
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:500 ]   _boost_PATH_SUFFIXES = boost-1_41_0;boost-1_41;boost-1_40_0;boost-1_40;boost-1_39_0;boost-1_39;boost-1_38_0;boost-1_38;boost-1_37_0;boost-1_37;boost-1_36_1;boost-1_36_0;boost-1_36;boost-1_35_1;boost-1_35_0;boost-1_35;boost-1_34_1;boost-1_34_0;boost-1_34;boost-1_33_1;boost-1_33_0;boost-1_33
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:524 ] location of version.hpp: /home/kknox/sdk/boost_1_44_0/boost/version.hpp
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:543 ] version.hpp reveals boost 1.44.0
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:634 ] guessed _boost_COMPILER = -gcc44
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:644 ] _boost_MULTITHREADED = -mt
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:661 ] _boost_STATIC_TAG =
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:663 ] _boost_ABI_TAG = d
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:696 ] _boost_LIBRARIES_SEARCH_DIRS = /home/kknox/sdk/boost_1_44_0/stage/lib;/home/kknox/sdk/boost_1_44_0/lib;/home/kknox/sdk/boost_1_44_0/stage/lib;/home/kknox/sdk/boost_1_44_0/lib;/home/kknox/sdk/boost_1_44_0/../lib;C:/boost/lib;C:/boost;/boost/boost_1_44_0/lib;/boost/boost_1_44/lib;/boost/lib;/boost;/sw/local/lib
-- [ /home/kknox/bin/cmake-2.8.2-Linux-i386/share/cmake-2.8/Modules/FindBoost.cmake:830 ] Boost_FOUND = TRUE
-- Boost version: 1.44.0
-- Found the following Boost libraries:
--   program_options

At my link step, I get:

/usr/bin/c++   -m32  -g   CMakeFiles/clAmd.Client.dir/clAmd.client.cpp.o CMakeFiles/clAmd.Client.dir/clAmd.openCL.cpp.o CMakeFiles/clAmd.Client.dir/clAmd.statisticalTimer.cpp.o CMakeFiles/clAmd.Client.dir/stdafx.cpp.o  -o clAmd.Client-0.5.1 -rdynamic -L/usr/src/ati/ati-stream-sdk-v2.2-lnx64/lib/x86 ../library/libclAmd.Runtime.so.0.5.1 -Wl,-Bstatic -lboost_program_options-mt -Wl,-Bdynamic -lOpenCL -Wl,-rpath,/usr/src/ati/ati-stream-sdk-v2.2-lnx64/lib/x86:/home/kknox/code/clTest/trunk/clFFT/bin/linux32/library:
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../libboost_program_options-mt.a when searching for -lboost_program_options-mt
/usr/bin/ld: skipping incompatible /usr/lib/libboost_program_options-mt.a when searching for -lboost_program_options-mt
/usr/bin/ld: cannot find -lboost_program_options-mt

Notice, that the link step does NOT use the paths that I specified, but instead uses '-Wl,-Bstatic -lboost_program_options-mt', which is using the boost that is installed in /usr/lib.  This is a problem because it is the wrong bitness.

Sorry for the big mess of output text, hope it is readable.  Does anybody know what to do?

Kent

-----Original Message-----
From: Knox, Kent 
Sent: Friday, October 29, 2010 4:40 PM
To: 'cmake at cmake.org'
Subject: Linking Boost on Linux on 64bit host and 32bit target

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