c++ - CMake FindBoost.cmake MinGW-W64 : searching for library with incorrect name

标签 c++ windows boost cmake cmake-modules

我已经构建了 Boost 1.68(使用来自 https://gist.github.com/sim642/29caef3cc8afaa273ce6 的说明,并将 link=static,shared 添加到 b2 命令行以同时构建共享库。)

这些库似乎构建正确,并且我已正确设置 BOOST_INCLUDEDIRBOOST_LIBRARYDIR 环境变量。

但是,当我将以下内容添加到 CMakeLists.txt 时:

find_package(Boost REQUIRED COMPONENTS system context coroutine thread random REQUIRED)

并使用 MinGW Makefiles 生成,我收到以下错误:

CMake Error at C:/Users/pbelanger/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/182.4129.15/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:2044 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.68.0

  Boost include path: C:/boost/install/include/boost-1_68

  Could not find the following static Boost libraries:

          boost_system
          boost_context
          boost_coroutine
          boost_thread
          boost_random

  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.

我在此处的 find_package 行之前放置了添加 set(Boost_DEBUG ON) 的输出:https://pastebin.com/yRd5DPt4

根据调试输出,查找脚本在正确的目录 (c:\boost\install\lib) 中搜索,但没有找到 boost 库,因为它们具有不同的命名方案.例如,system 库名为 libboost_system-mgw81-mt-x64-1_68.dll,但查找脚本传递的是库名称 boost_system-mgw81- mt-1_68 到 CMake 的 find_library。请注意,寻址模型 (-x64) 未在后一个名称中列出。

我的问题是这是否是 Boost 或 findCMake 脚本的问题?可以通过在 findCMake 脚本之前设置特定的 cmake 变量来解决这个问题吗?

最佳答案

经过数小时的研究,Paul Belanger 给出的答案拯救了我。

在代码库中进一步挖掘,他们添加了一个新选项来管理这种情况,因此使用最新版本的 CMAKE,您可以添加以下选项:

set (Boost_ARCHITECTURE "-x64")

来源:https://github.com/Kitware/CMake/commit/1e08b625c291e0bb57d253b6656e812dc8848bd8#diff-555801259d7df67368f7deab1f9deacd

关于c++ - CMake FindBoost.cmake MinGW-W64 : searching for library with incorrect name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51900290/

相关文章:

c - 我无法使用 SHFileOperation 删除文件

windows - 如何从 Subversion 存储库中删除意外放置的大文件 (4GB)?

c++ - 如何改进此模板以在 VS2012 中接受 lambda

C++延迟任务

具有 1 个参数的 C++ 默认模板化构造函数

c++ - 如何设置蓝色边框来编辑控件?

c++ - boost::interprocess shared memory segment function find() 如果段已经存在则在启动时挂起

c++ - 构建 CUDA/C++ 代码时链接器错误

windows - EasyPHP 和 Windows 8 端口 127.0.0.1 问题

c++ - 从 boost::array 更改为 std::array 时出现错误