CMake and Boost

I searched and found out that many people have the same problem, but there is no solution.

I use CMake to create a Makefile for MinGW, and when compiling I get an error:

CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x5e): undefined reference to `_imp___ZN5boost6thread4joinEv'
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x71): undefined reference to `_imp___ZN5boost6threadD1Ev'
CMakeFiles\boosttest.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x88): undefined reference to `_imp___ZN5boost6threadD1Ev'

This seems to be a binding problem, I understand. My CMake configuration:

project(boosttest)
cmake_minimum_required(VERSION 2.6)

include_directories(${boosttest_SOURCE_DIR}/include c:/boost_1_48_0/)
link_directories(c:/boost_1_48_0/lib)

file(GLOB_RECURSE cppFiles src/*.cpp)

add_executable(boosttest ${cppFiles})

target_link_libraries(boosttest libboost_thread-mgw46-mt-1_48.a)

At first I tried to use find_package(Boost COMPONENTS thread), and it worked the same way, so I decided to try it manually, and I still get the same error.

Any ideas on this?

I compiled it for mingw using bjam and as a static link. Also tried to do:

add_library(imp_libboost_thread STATIC IMPORTED)
set_property(TARGET imp_libboost_thread PROPERTY IMPORTED_LOCATION c:/boost_1_48_0/lib/libboost_thread-mgw46-mt-1_48.a)
target_link_libraries(boosttest imp_libboost_thread)

And I still get the same error messages.

+5
source share
2 answers

mingw32 BOOST_THREAD_USE_LIB. boost:: thread . Threads ( , , * nix).

CMakeLists. , boost:: thread mingw-gcc ( ):

    set(Boost_USE_STATIC_LIBS   ON)
    set(Boost_USE_MULTITHREADED ON)
    set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0")
    find_package(Boost COMPONENTS thread date_time program_options filesystem system REQUIRED)
    include_directories(${Boost_INCLUDE_DIRS})

    find_package(Threads REQUIRED)

    #...

    if (WIN32 AND __COMPILER_GNU)
        # mingw-gcc fails to link boost::thread
        add_definitions(-DBOOST_THREAD_USE_LIB)
    endif (WIN32 AND __COMPILER_GNU)

    #...

    target_link_libraries(my_exe
            ${CMAKE_THREAD_LIBS_INIT}
            #...
        ${Boost_LIBRARIES}
    )
+10

, . , , .

find_package (Boost) :

project(boosttest)
cmake_minimum_required(VERSION 2.6)

# Play with the following defines
# Disable auto-linking. 
add_definition( -DBOOST_ALL_NO_LIB )
# In case of a Shared Boost install (dlls), you should then enable this
# add_definitions( -DBOOST_ALL_DYN_LINK )

# Explicitly tell find-package to search for Static Boost libs (if needed)
set( Boost_USE_STATIC_LIBS ON ) 
find_package( Boost REQUIRED COMPONENTS thread )

include_directories( ${Boost_INCLUDE_DIRS} )

file(GLOB_RECURSE cppFiles src/*.cpp)

add_executable(boosttest ${cppFiles})

target_link_libraries(boosttest ${Boost_LIBRARIES} )
+3

All Articles