【问题标题】:Cannot find boost libraries with cmake无法使用 cmake 找到 boost 库
【发布时间】:2017-05-11 15:01:06
【问题描述】:

我已经在 Windows 上安装了 boost 1.63.0,我正在尝试使用 CMake 构建(使用 Visual Studio 2017 作为生成器)。我无法让 find_package() 找到我的 boost 库,我不知道为什么。

CMakeLists.txt:

find_package(Boost REQUIRED COMPONENTS system filesystem thread)

输出:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.8/Modules/FindBoost.cm
ake:1813 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.63.0

  Boost include path: C:/Program Files (x86)/boost/boost_1_63_0

  Could not find the following Boost libraries:

          boost_system
          boost_filesystem
          boost_thread

  Some (but not all) of the required Boost libraries were found.  You may
  need to install these additional Boost libraries.  Alternatively, set
  BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
  to the location of Boost.

Boost 查找包含,但不查找库。标头位于: %BOOST_ROOT%。图书馆位于%BOOST_ROOT%/stage/lib。当我查看_boost_LIBRARY_SEARCH_DIRS_RELEASE 时,它首先看到的是正确的位置。为了确定,我还尝试将BOOST_LIBRARYDIR 硬编码到该路径。

为了安装 boost,我将下载的存档解压缩到 %BOOST_ROOT%,然后运行 ​​bootstrap.\b2 link=static,shared threading=single,multi。这应该给我所有版本的库。在 boost:system 的情况下,我在%BOOST_ROOT%/stage/lib% 中有以下二进制文件:

boost_system-vc100-mt-1_63.dll
boost_system-vc100-mt-1_63.lib
boost_system-vc100-mt-gd-1_63.dll
boost_system-vc100-mt-gd-1_63.lib
libboost_system-vc100-mt-1_63.lib
libboost_system-vc100-mt-gd-1_63.lib

我尝试启用和禁用以下功能,但无济于事:

set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_MULTITHREADED OFF )
set( Boost_DEBUG ON )

这是一个有趣的部分。 Boost_DEBUG 参数吐出这一行:

Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_63;boost_system-vc141-mt;boost_system-mt-1_63;boost_system-mt;boost_system

请注意 vc141 与 vc100。我认为 .\b2 为 vc100 构建了一些东西。这很奇怪,因为我是从 VS 2017 的开发命令提示符运行它。我进行了疯狂的猜测并尝试使用 ./b2 toolset=msvc-14.1 构建提升,但我收到一个错误:*** argument error * rule maybe-rewrite-setup ( toolset : setup-script : setup-options : version : rewrite-setup ? )".

如何确保我使用 VS2017 或 MSVC141 编译 boost?

这个线程似乎相关: Version numbers for Visual Studio 2017, Boost and CMake

【问题讨论】:

  • 您提到的帖子建议使用b2 toolset=msvc-14.1 构建Boost(“msvc”和版本部分用破折号分隔,而不是等号)。
  • 找到建议两种方式的帖子。两种方式都试过了。感谢您的建议,但似乎没有什么不同。

标签: c++ boost cmake


【解决方案1】:

检查正在使用的FindBoost.cmake 脚本。根据您使用的 CMake 版本,可能无法处理此版本的 Boost。库之间的依赖关系是根据找到的 Boost 版本设置的。

例如,CMake 源代码中最新版本的脚本 on GitHub 处理版本 1.63。我遇到了无法处理它的 CMake v3.6.2 的问题。

关于 MSVC 的版本不匹配我不知道,对不起。

【讨论】:

  • 谢谢,自 3.6 以来我还没有更新 cmake。所以你的回答听起来很合理。我会在星期一回去工作时检查一下。
  • 将 CMake 更新到 3.8。它知道我已经安装了 VS2017,所以它仍然在寻找 msvc-141 二进制文件。当我调用 boostrap & b2 时,它只构建 msvc-100 二进制文件。此解决方案无效。
【解决方案2】:

我编译了 boost,并且正在使用相同的工具集编译链接应用程序。因此,我决定将所有已编译的库从 *-vc100-* 重命名为 *-vc141-* 是安全的。虽然通常我会劝阻(你可能会在 ABI 中得到细微的差异),但在这种情况下,我确信它是同一个编译器,因此很明显 cmake 或 b2 有一个错误,它创建(或搜索)了一个文件名字不对。

这样做之后,cmake不仅找到了boost,而且链接成功了。

【讨论】:

  • 这适用于很多情况(包括我链接 boost::log 的情况)。但是,当我使用 -DUNICODE 编译项目时,我收到错误 LNK2038:检测到“boost_log_abi”不匹配:值“v2_mt_nt5”与值“v2_mt_nt6”不匹配。所以仍然可能存在问题。
猜你喜欢
  • 2014-08-02
  • 1970-01-01
  • 2017-06-23
  • 2011-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多