我正在尝试通过使用CMake创建MSVC9.0项目文件来构建具有boost库的应用程序.
我收到以下错误:
错误3致命错误LNK1104:无法打开文件'libboost_system-vc90-mt-gd-1_44.lib'
这是CMake配置
cmake_minimum_required(VERSION 2.8)
PROJECT( TestProject)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
set(BOOST_ROOT "D:/boost_1_44_0")
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE( Boost 1.44.0 REQUIRED unit_test_framework system)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${BOOST_ROOT})
LINK_DIRECTORIES(${LINK_DIRECTORIES} "D:/boost_1_44_0/stage/lib")
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
SET(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
ADD_EXECUTABLE(testapp
main.cpp)
TARGET_LINK_LIBRARIES(testapp
${Boost_SYSTEM_LIBRARY}
)
SET_TARGET_PROPERTIES( testapp PROPERTIES DEBUG_POSTFIX "d" )
Run Code Online (Sandbox Code Playgroud)
我已经使用以下选项为静态和共享(调试和发布)构建了增强功能.
bjam toolset=msvc variant=debug link=shared runtime-link=shared threading=multi --build-type=complete stage
bjam toolset=msvc variant=release link=shared runtime-link=shared threading=multi --build-type=complete stage
bjam toolset=msvc variant=debug link=static runtime-link=static threading=multi --build-type=complete stage
bjam toolset=msvc variant=release link=static runtime-link=static threading=multi --build-type=complete stage
Run Code Online (Sandbox Code Playgroud)
我不确定我在配置中缺少什么.有什么建议?谢谢.
我搜索并发现很多人都有同样的问题,但没有解决方案.
我正在使用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)
我仍然得到相同的错误消息.