Boost 1.59 linker error

663 Views Asked by At

I have a local install of the Boost libraries (specifically version 1.59) on an older install of Ubuntu 11.04 I have set it up so that the install is in my home directory in the following location:

${HOME}/boost_1_59

I am using the following CMake file to compile and build the program that I am working on:

cmake_minimum_required( VERSION 2.8 )

project( myproject C CXX )

set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib )

set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -pthread" )

set( BOOST_ROOT "/home/user/boost_1_59" )

set( BOOST_MIN_VERSION          "1.59" )
set( Boost_USE_MULTITHREADED    ON )
set( Boost_USE_STATIC_LIBS      ON )

find_package( Boost ${BOOST_MIN_VERSION} COMPONENTS filesystem thread system REQUIRED )

if( Boost_FOUND )
    set( BOOST_LIBRARYDIR "/home/user/boost_1_59/lib" )
    set( BOOST_INCLUDEDIR "/home/user/boost_1_59/include" )

    INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

    add_executable( TorcPause main.cpp )
    target_link_libraries( TorcPause ${Boost_LIBRARIES} )
endif()

When I attempt to compile the project I get the following linker errors (I always wipe out the "build" directory to ensure that CMake is not pulling from cache as this is a known issue when trying to use boost with CMake):

CMakeFiles/TorcPause.dir/TorcPause.cpp.o: In function `boost::asio::error::get_system_category()':
TorcPause.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x5): undefined reference to `boost::system::system_category()'
CMakeFiles/TorcPause.dir/TorcPause.cpp.o: In function `boost::thread_exception::thread_exception(int, char const*)':
TorcPause.cpp:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x14): undefined reference to `boost::system::system_category()'
CMakeFiles/TorcPause.dir/TorcPause.cpp.o: In function `boost::condition_error::condition_error(int, char const*)':
TorcPause.cpp:(.text._ZN5boost15condition_errorC2EiPKc[_ZN5boost15condition_errorC5EiPKc]+0x14): undefined reference to `boost::system::system_category()'
CMakeFiles/TorcPause.dir/TorcPause.cpp.o: In function `boost::thread::start_thread()':
TorcPause.cpp:(.text._ZN5boost6thread12start_threadEv[boost::thread::start_thread()]+0x15): undefined reference to `boost::thread::start_thread_noexcept()'
CMakeFiles/TorcPause.dir/TorcPause.cpp.o: In function `boost::thread::join()':
TorcPause.cpp:(.text._ZN5boost6thread4joinEv[boost::thread::join()]+0x6d): undefined reference to `boost::thread::join_noexcept()'
libTorcIOManager.a(IOManager.cxx.o): In function `__static_initialization_and_destruction_0(int, int)':
IOManager.cxx:(.text+0x2fd): undefined reference to `boost::system::generic_category()'
IOManager.cxx:(.text+0x309): undefined reference to `boost::system::generic_category()'
IOManager.cxx:(.text+0x315): undefined reference to `boost::system::system_category()'
libTorcIOManager.a(IOManager.cxx.o): In function `boost::system::error_code::error_code()':
IOManager.cxx:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
libTorcConnection.a(Connection.cxx.o): In function `__static_initialization_and_destruction_0(int, int)':
Connection.cxx:(.text+0x17c0): undefined reference to `boost::system::generic_category()'
Connection.cxx:(.text+0x17cc): undefined reference to `boost::system::generic_category()'
Connection.cxx:(.text+0x17d8): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make[2]: *** [../bin/TorcPause] Error 1
make[1]: *** [CMakeFiles/TorcPause.dir/all] Error 2
make: *** [all] Error 2

As you can see from my CMake file I am including the boost system library and so I am not sure what I am doing wrong or what I need to change in order to make this work properly.

Update #1: As requested here is the output of running make VERBOSE=1

CMake & make VERBOSE=1 command line output

1

There are 1 best solutions below

0
m.s. On BEST ANSWER

There are two problems:

  1. Your linker invocation shows that the linker does not search the libraries in your custom library directory. Hence you need to add LINK_DIRECTORIES(${BOOST_LIBRARYDIR})

  2. Additionally, since Boost_USE_MULTITHREADED is enabled, the multithreaded versions of the boost libraries (libboost_...-mt.a) need to exist in your custom library directory. As you stated, those did not exist, so you need to recompile boost with multithread support enabled.