CMake无法找到Boost Libraries(VS 2017)

时间:2018-04-25 19:45:26

标签: c++ cmake visual-studio-2017

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

# 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,它正在编译它。

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"

My Boost Library目录如下所示 enter image description here

Visual Studio CMake的输出是:

 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)

1 个答案:

答案 0 :(得分:2)

重新制定我以前的评论作为答案:

由于命名方案的更改,

Boost 1.66.0无法在3.11.0 CMake个版本上运行。如果您必须使用此特定版本,则需要安装合适的CMake版本(3.11.0或更新版本)并使用它生成解决方案。否则,Boost 1.65.1是开箱即用的最后一个已知版本,并且与CMake 3.10完美无瑕。

要了解Boost可以处理的CMake版本,请查看Modules目录中的FindBoost.cmake并搜索_Boost_KNOWN_VERSIONS变量。