c++ - 在 Windows 上使用 MinGW 构建时,cmake FindBoost 找不到 Boost 库

标签 c++ boost cmake

qtcreator同时支持qmakecmake进行跨平台开发和 qmake 适用于 msvcMinGWWindows 上构建。但是,我更愿意只支持一种工具:cmake

CMakeLists.txt 位于 via-httpliblinux 上以及在 Windows 上使用 cmake 构建 msvc 时工作正常。 但是,在 Windows 上使用 cmake 构建 MinGW 时,出现以下错误:

CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
Unable to find the requested Boost libraries.

Boost version: 1.69.0

Boost include path: D:/DevLibraries/boost/boost_1_69_0

Could not find the following Boost libraries:

      boost_system

No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.

BOOST_LIBRARYDIRBOOST_ROOT 环境变量均已设置并在使用 Visual Studio 15 2017 Win64 生成器和默认 native 编译器时找到

错误消息表明,当使用 MinGW Makefiles 和默认 native 编译器时,cmake 找到了 BOOST_ROOT 环境变量,但没有找到 BOOST_LIBRARYDIR。所以它似乎与此处描述的问题不同:Cmake doesn't find Boost

这是 FindBoost.cmake 中的错误吗?有“变通办法”吗?

最佳答案

这是 FindBoost.cmake 中的 _boost_ARCHITECTURE_TAG 的问题,如第 1518 行所述。
添加该标签是为了处理 Boost 1.66.0 及更高版本。

它没有将 MinGW_boost_ARCHITECTURE_TAG 设置为 -x64,因此它正在搜索 boost 库名称,例如:

libboost_system-mgw73-mt-d-1_69.a

代替:

libboost_system-mgw73-mt-d-x64-1_69.a

有一个解决方法:将 cmake 变量:Boost_ARCHITECTURE 设置为 -x64

注意:将 Boost_ARCHITECTURE 设置为环境变量不起作用,因为 FindBoost.cmake 不会将 Boost_ARCHITECTURE 读取为环境变量。

关于c++ - 在 Windows 上使用 MinGW 构建时,cmake FindBoost 找不到 Boost 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53943885/

相关文章:

c++ - 使用 g++ 时 HDF5 的 undefined symbol

c++ - 推导重载函数的类型 - currying

c++ - 链接器在链接静态库时可以省略目标文件吗?

python - nng支付nng pub/sub。客户端未收到任何消息

c++ - 是否有完整的基于范围的标准库实现?

C++ 格式化日期

Boost graph - 移除顶点后,顶点仍然存在

c++ - CMake错误: Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS) using clang on Mac OS

c++ - 在 C++ 中生成具有固定总和的随机值

c++ - CMake 编译失败