Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost log, GCC 4.4 and CMake

I am trying to get a simple boost.log example running on Linux using GCC 4.4.5, CMake 2.8.2 and Boost 1.53.0.

Compiling boost and boost log succeeded, but I keep getting issues when linking my test program to boost.log.

I use the following CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)

project(QuantibBoostLogTest)

# Include boost headers
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Threads)
find_package(Boost 1.53.0 COMPONENTS thread date_time filesystem system log log_setup REQUIRED)
if(Boost_FOUND)
  include_directories( ${Boost_INCLUDE_DIRS} )
  link_libraries(${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
else(Boost_FOUND)
  message(FATAL_ERROR "Cannot build Quantib Boost Log test without Boost. Please set Boost_DIR.")
endif(Boost_FOUND)

add_executable(quantibBoostLogTest boost_log_test.cxx)
install(TARGETS quantibBoostLogTest DESTINATION .)

CMake does detect the boost libraries correctly, but I still get linker errors, mostly of the form:

core.cpp:(.text+0x1b0e): undefined reference to `boost::detail::get_tss_data(void const*)'

I do link the thread libraries. Does anybody know how to solve this?

like image 657
Coert Metz Avatar asked May 14 '13 09:05

Coert Metz


2 Answers

It seems like boost.log depends on boost.thread library then you need change order of libraries. See why link order does matter

Try following order

find_package(Boost 1.53.0 COMPONENTS log log_setup thread date_time filesystem system REQUIRED)

if it will not help try include them two times as following

link_libraries(${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${Boost_LIBRARIES})
like image 114
Nikolay Viskov Avatar answered Sep 19 '22 13:09

Nikolay Viskov


The linker error you give has something to do with either not linking against a native threading library like pthreads and/or boost_thread. (or both)

1) From what I see you don't link against pthreads library.
By merely calling a CMake custom module that tries to find the library doesn't mean it'll also link against it.

Try and do:

SET(CMAKE_THREAD_PREFER_PTHREAD true)
FIND_PACKAGE (Threads)
IF(Threads_FOUND)
INCLUDE_DIRECTORIES(SYSTEM ${Threads_INCLUDE_DIR})
MESSAGE("Are we using pthreads? ${CMAKE_USE_PTHREADS_INIT}")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
ENDIF()

Check the FindThreads.cmake file of the CMake installation you have for more information regarding the use of the threads module. You can usually find it in /usr/share/cmake-2.8/Modules/

2) Maybe the ordering of the linked Boost libraries is incorrect or the version you specified for Boost is invalid.

Try changing the boost version or don't specify it at all or change the order of the linked libraries

SET(Boost_USE_STATIC_LIBS ON)  
SET(Boost_USE_MULTITHREADED ON)  
FIND_PACKAGE(Boost 1.53.0 COMPONENTS **system thread filesystem date_time log log_setup** REQUIRED)  

IF(Boost_FOUND)  
    INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIR})  
    LINK_DIRECTORIES(${Boost_LIBRARY_DIR})  
    MESSAGE("Boost information")  
    MESSAGE("Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")  
    MESSAGE("Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")  
    MESSAGE("Boost Libraries: ${Boost_LIBRARIES}")  
    TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${Boost_LIBRARIES})  
ENDIF()

(The second contention might be completely wrong as I think the ordering of the elements specified after COMPONENTS in FIND_PACKAGE doesn't matter)

like image 45
Alex Bitek Avatar answered Sep 22 '22 13:09

Alex Bitek