无法使用 CMake 为 MSVC9 生成的项目文件链接到 boost 库 [英] Failed linking to boost library with CMake generated project file for MSVC9
问题描述
我正在尝试通过使用 CMake 创建 MSVC9.0 项目文件来构建具有 boost 库的应用程序.
I'm trying to build an application with boost library by creating a MSVC9.0 project files with CMake.
我收到以下错误:
错误 3 致命错误 LNK1104:无法打开文件 'libboost_system-vc90-mt-gd-1_44.lib'
Error 3 fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-gd-1_44.lib'
这里是 CMake 配置
Here is the CMake configuration
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" )
我使用以下选项为静态和共享(调试和发布)构建了 boost.
I have built boost for static and shared (debug and release) with following options.
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
我不确定配置中缺少什么.有什么建议?谢谢.
I'm not sure what I'm missing in the configuration. Any suggestions? Thanks.
推荐答案
首先,您是否检查过'libboost_system-vc90-mt-gd-1_44.lib"是否真的存在于您的 stage-dir D:/boost_1_44_0/stage/lib"?
First of all, did you check if "'libboost_system-vc90-mt-gd-1_44.lib" really exists in your stage-dir "D:/boost_1_44_0/stage/lib"?
第二:我曾经在使用 Boost 和 CMake 的 find_package(Boost) 时遇到的最常见问题是对自动链接的干扰.您可以通过向编译标志添加定义来禁用它
Second: the most common problem I used to have with Boost and CMake's find_package( Boost) was interference with the auto-linking. You could disable it by adding a definition to your compile flags
add_definitions( -DBOOST_ALL_NO_LIB )
但是您可能需要指定是要链接到动态版本还是静态版本
but then you probably will need to specify if you want to link to the dynamic or static version
set( Boost_USE_STATIC_LIBS ON ) # or Off, depending on what you want
find_package( Boost 1.44.0 REQUIRED unit_test_framework system)
当然,您可以随时检查生成的 Visual Studio 文件,以查看实际将哪些链接库添加到您的项目中.
Of course, you could always check the generated visual studio files to see which link-libraries are actually added to your project.
这篇关于无法使用 CMake 为 MSVC9 生成的项目文件链接到 boost 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!