【问题标题】:VS2013 always linking to 1.55.0 boost libraryVS2013 总是链接到 1.55.0 boost 库
【发布时间】:2014-09-30 23:55:18
【问题描述】:

我正在将我的代码迁移到 Visual Studio 2013 专业版(从 2005 年开始)。为此,我安装了 cmake 3.0.2(之前的 2.8 版本)并编译了 boost 1.56.0(之前的版本 1.47.0)。

CmakeList.txt 查找 boost 是:

# 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 设置为我的 boost 安装路径。

现在,当我构建我的项目时,它给了我如下链接错误:

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

我看到的问题是,我已经编译了 boost 1.56.0,但它正在尝试与 1.55.0 版本库链接。

我无法理解为什么会这样。

请帮忙。

编辑:我已经使用命令编译了我的 boost:

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

【问题讨论】:

    标签: boost visual-studio-2013 cmake


    【解决方案1】:

    这意味着您的代码需要 Boost 的 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})
    

    【讨论】:

    • 感谢您的回复。我无法理解的是,到目前为止,我不需要明确命名组件(直到我使用 1.47.0),但为什么现在我需要提及它?另外,按照您所说的,它将如何链接到 1.56.0 版本?我还需要提及版本吗?
    • @Garfield 版本无需赘述,只要将Boost路径设置为BOOST_ROOT环境即可。
    • 另外请注意,在 VS 上,Boost 将尝试自动链接库,这很容易被 CMake 破坏。所以请务必将BOOST_ALL_NO_LIB 添加到您的预处理器定义中。
    猜你喜欢
    • 2014-08-11
    • 1970-01-01
    • 2017-05-15
    • 2012-05-03
    • 2011-12-28
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多