我搜索并发现很多人都有同样的问题,但没有解决方案.
我正在使用CMake为MinGW生成Makefile,在编译时我收到错误:
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'
Run Code Online (Sandbox Code Playgroud)
这似乎是一个链接问题,我明白了.我的CMake配置是:
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)
Run Code Online (Sandbox Code Playgroud)
首先我尝试使用find_package(Boost COMPONENTS thread)它,它的工作方式相同,所以我想尝试手动执行此操作,但仍然会遇到相同的错误.
有什么见解吗?
我使用bjam编译它为mingw并作为静态链接.还试过做:
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)
Run Code Online (Sandbox Code Playgroud)
我仍然得到相同的错误消息.