【发布时间】: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”和版本部分用破折号分隔,而不是等号)。 -
找到建议两种方式的帖子。两种方式都试过了。感谢您的建议,但似乎没有什么不同。