2014-09-30 61 views
0

我正在将我的代码迁移到Visual Studio 2013专业版(从2005年开始)。为此,我安装了cmake 3.0.2(以前的版本2.8)和编译boost 1.56.0(以前的版本1.47.0)。VS2013总是链接到1.55.0增强库

CmakeList.txt找到提升是:

# find the boost installed path from environment variable 
set(BOOST_ROOT_DIR "$ENV{BOOST_ROOT_DIR}") 
if(BOOST_ROOT_DIR) 
    message("Boost found at ${BOOST_ROOT_DIR}") 
else(BOOST_ROOT_DIR) 
    set(BOOST_ROOT_DIR "$ENV{BOOST_ROOT}") 
    if(BOOST_ROOT_DIR) 
    else(BOOST_ROOT_DIR) 
    message(FATAL_ERROR "BOOST is not installed") 
    endif() 
endif(BOOST_ROOT_DIR) 
include_directories("${BOOST_ROOT_DIR}") 

在这里,环境变量BOOST_ROOT_DIR被设置为安装我的提升路径。

现在,当我建立我的项目,它给我链接错误,如:

LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc120-mt-s-1_55.lib' 

我看到的问题是,我有编译升压1.56.0,但它正试图与1.55链接.0版本库。

我不明白为什么会发生这种情况。

请帮忙。

编辑:我编使用命令我升压:

bjam --toolset=msvc-12.0 variant=debug,release link=static runtime-link=static address-model=64 

回答

0

这意味着你的代码需要升压转换器的thread成分(其他类似),您需要为包括CMakeLists.txt这样的:

set(Boost_USE_STATIC_LIBS ON) 
find_package(Boost REQUIRED thread) # name the needed components explicitly 
include_directories(${Boost_INCLUDE_DIRS}) 
link_directories(${Boost_LIBRARY_DIR}) 
target_link_libraries(yourProject ${Boost_LIBRARIES}) 
+0

感谢您的回复。我无法理解的是,到现在为止,我不需要明确命名组件(直到我使用1.47.0),但为什么现在我需要提及它呢? 另外,通过你所说的话,它将如何链接到1.56.0版本?我是否也需要提及版本? – Garfield 2014-10-01 05:46:56

+0

@Garfield只要将Boost路径设置为'BOOST_ROOT'环境,就不需要提及版本。 – herohuyongtao 2014-10-01 05:49:12

+3

另外请注意,在VS上,Boost会尝试自动链接库,这可以很容易地与CMake打破。所以一定要将'BOOST_ALL_NO_LIB'添加到你的预处理器定义中。 – ComicSansMS 2014-10-01 07:47:39