CMake无法找到Boost库(VS 2017) [英] CMake unable to find Boost Libraries(VS 2017)

查看:248
本文介绍了CMake无法找到Boost库(VS 2017)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Studio 2017创建CMake项目。我想将Boost添加到项目中。虽然可以找到Boost,但是找不到所需的组件。我的CMake看起来像这样。

I am attempting to create a CMake project with Visual Studio 2017. I want to add Boost to the project. While I can find Boost, it is unable to find the required components. My CMake looks like so.

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.10)

project ("FirstProject")

#This project heavily uses C++ 17
set (CMAKE_CXX_STANDARD 17)

#TESTING various flags to try and get it to work.
set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)

#Error calls for setting this, but doesn't work regardless.
set(BOOST_LIBRARYDIR "${BOOST_ROOT}/stage/lib")
find_package(Boost 1.66.0 REQUIRED COMPONENTS filesystem)
if(Boost_FOUND)
    message(WARNING "HERE!!")
endif()


# Include sub-projects.
add_subdirectory ("TestSubProject")

鉴于我是Visual Studio,它正在编译

Given that I am Visual Studio it is compiling it like so.

cmake.exe  -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\User\CMakeBuilds\Hash\install\x86-Debug" \
-DBOOST_ROOT="D:/Programming_Projects/C++/Dir/ProjectDir/3rdPartyLibraries/boost_1_66_0" \
-DBoost_COMPILER="vc141" \
-DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/HostX86/x86/cl.exe" \
-DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/HostX86/x86/cl.exe" \
-DCMAKE_BUILD_TYPE="Debug" \
-DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "D:\Programming_Projects\C++\Dir\ProjectDir"

我的Boost库目录看起来像

My Boost Library directory looks like

Visual Studio CMake的输出为:

The output from Visual Studio CMake is:

 CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:796 (message):
   New Boost version may have incorrect or missing dependencies and imported
   targets
 Call Stack (most recent call first):
   C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake(902): (_Boost_COMPONENT_DEPENDENCIES)
   C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake(1537): (_Boost_MISSING_DEPENDENCIES)
   CMakeLists.txt(20): (find_package)


 CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:796 (message):
   New Boost version may have incorrect or missing dependencies and imported
   targets
 Call Stack (most recent call first):
   C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake(902): (_Boost_COMPONENT_DEPENDENCIES)
   C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake(1537): (_Boost_MISSING_DEPENDENCIES)
   CMakeLists.txt(20): (find_package)


 CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:1923 (message):
   Unable to find the requested Boost libraries.

   Boost version: 1.66.0

   Boost include path:
   D:/Programming_Projects/C++/Dir/ProjectDir/3rdPartyLibraries/boost_1_66_0


   Could not find the following static Boost libraries:

           boost_filesystem

   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.
Call Stack (most recent call first):
  CMakeLists.txt(20): (find_package)

-- Configuring incomplete, errors occurred!
See also "C:/Users/User/CMakeBuilds/57d076a1-4dfa-ba3f-98a5-b87b55e6d381/build/x86-Debug/CMakeFiles/CMakeOutput.log".
 C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe  -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\Christopher\CMakeBuilds\57d076a1-4dfa-ba3f-98a5-b87b55e6d381\install\x86-Debug"  -DBOOST_ROOT="D:/Programming_Projects/C++/Dir/ProjectDir/3rdPartyLibraries/boost_1_66_0"  -DBoost_COMPILER="vc141"  -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/HostX86/x86/cl.exe"  -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/HostX86/x86/cl.exe"  -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "D:\Programming_Projects\C++\Dir\ProjectDir" returned with exit code: 1
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:796 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:902 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:1537 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:20 (find_package)
CMake Warning at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:796 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:902 (_Boost_COMPONENT_DEPENDENCIES)
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:1537 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:20 (find_package)
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.10/Modules/FindBoost.cmake:1923 (message):
  Unable to find the requested Boost libraries.
  Boost version: 1.66.0
  Boost include path:
  D:/Programming_Projects/C++/Dir/ProjectDir/3rdPartyLibraries/boost_1_66_0
  Could not find the following static Boost libraries:
          boost_filesystem
  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.
Call Stack (most recent call first):
  CMakeLists.txt:20 (find_package)


推荐答案

将我之前的评论重新整理为答案:

Reformulating my previous comments as answer:

提升1.66.0 3.11.0 CMake 之前的版本中不起作用。如果必须使用此特定版本,则需要安装合适的 CMake 版本( 3.11.0 或更高版本)并生成解决方案。否则, Boost 1.65.1 是最后一个可用的现成版本,并且 CMake 3.10 完美无缺。

Boost 1.66.0 does not work on pre 3.11.0 CMake versions because of changes in the naming scheme. If you have to use this specific version then you need to install a suitable CMake version (3.11.0 or newer) and generate the solution with it. Otherwise Boost 1.65.1 is the last known version to work out of the box and flawlessly with CMake 3.10.

要了解您的 CMake 可以得到哪些 Boost 版本请在Modules目录中查看FindBoost.cmake并搜索 _Boost_KNOWN_VERSIONS 变量。

To find out what Boost versions your CMake can handle please have a look into FindBoost.cmake in Modules directory and search for _Boost_KNOWN_VERSIONS variable.

这篇关于CMake无法找到Boost库(VS 2017)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆