我已经构建了 Boost 1.68(使用来自 https://gist.github.com/sim642/29caef3cc8afaa273ce6 的说明,并将 link=static,shared
添加到 b2 命令行以同时构建共享库。)
这些库似乎构建正确,并且我已正确设置 BOOST_INCLUDEDIR
和 BOOST_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")
关于c++ - CMake FindBoost.cmake MinGW-W64 : searching for library with incorrect name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51900290/