【发布时间】:2012-03-04 12:24:02
【问题描述】:
我搜索了很多人都有同样的问题,但没有解决方案。
我正在使用 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'
这似乎是一个链接问题,我明白了。我的 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)
首先我尝试使用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)
我仍然收到相同的错误消息。
【问题讨论】:
标签: boost cmake boost-thread