Boost log, GCC 4.4 and CMake

前端 未结 2 1155
[愿得一人]
[愿得一人] 2021-02-07 08:39

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

相关标签:
2条回答
  • 2021-02-07 09:28

    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)

    0 讨论(0)
  • 2021-02-07 09:45

    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})
    
    0 讨论(0)
提交回复
热议问题