CMake发现Boost但没有请求库

时间:2018-03-12 02:50:40

标签: c++ boost cmake

我正在尝试使用CMake将Boost添加到C ++应用程序中。我已经阅读了所有可以在SO上找到的相关问题,我觉得我越来越接近解决方案了。但由于某些原因,CMake仍无法找到所请求的Boost库。

我正在尝试找到“boost_filesystem”。调试显示CMake正在寻找“boost_filesystem-vc141-mt-gd-1_65_1”。我的文件夹“C:\ boost \ boost_1_65_1 \ stage \ lib”中有“libboost_filesystem-vc141-mt-gd-1_65_1.lib”文件。我想这是CMake正在寻找的文件,但由于某些原因,CMake说它无法找到它。

这是我用来构建Boost的过程。对于大多数人来说这可能是太多的细节,但我怀疑它可能对另一个新手有帮助。

  1. 在文件夹C:\ boost \ boost_1_65_1
  2. 中下载并解压缩Boost 1.65.1
  3. 转到开发人员提示命令行并在上面的文件夹下运行bootstrap.bat。
  4. 在C:\ boost \ boost_1_65_1 \ boost \ config \ compiler下更新了visualc.hpp文件(参见Unknown compiler version while compiling Boost with MSVC 14.0 (VS 2015)
  5. 替换了visualc.hpp文件底部的行:

    // last known and checked version is 19.11.25506 (VC++ 2017.3):
    #if (_MSC_VER > 1911)
    

    // last known and checked version is 19.13.26128 (VC++ 2017.5.6):
    #if (_MSC_VER > 1913)
    
    1. 在文件夹boost_1_65_1下打开另一个文件project-config.jam,并将第二行更新为以下内容:

      使用msvc:14.1:“C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Professional \ VC \ Tools \ MSVC \ 14.13.26128 \ bin \ Hostx64 \ x64 \ cl.exe“;

    2. 返回开发人员提示命令行并运行以下命令来构建Boost:

      b2 toolset = msvc-14.1 address-model = 64

    3. 我似乎已正确完成以下项目:

      • 正确构建了库,但未使用默认目录。我确认建立了所请求的库。
      • 将路径正确分配给CMake指定目录
      • 正确使用了CMake find_package()

      以下是我使用的相关版本:

      • VS:2017 v15.6.1 with CMake 3.10
      • Boost版本:1.65.1,使用工具MSVC 14.1构建

      这是CMakelist.txt:

      cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
      project(test)
      
      set(Boost_USE_STATIC_LIBS       OFF)
      set(Boost_USE_MULTITHREADED      ON)
      set(Boost_USE_STATIC_RUNTIME    OFF)
      
      set(Boost_DEBUG ON)
      
      set(BOOST_ROOT C:\\boost\\boost_1_65_1)
      set(BOOST_INCLUDEDIR C:\\boost\\boost_1_65_1)
      set(BOOST_LIBRARYDIR C:\\boost\\boost_1_65_1\\stage\\lib)
      
      set(Boost_DEBUG 1)
      
      find_package(Boost COMPONENTS filesystem REQUIRED)
      
      message(STATUS "Boost LIBRARIES: " ${Boost_LIBRARIES})   
      add_executable(test_Boost main.cpp)
      target_link_libraries(test_Boost ${Boost_LIBRARIES})
      

      这是可能相关的输出的一部分:

      1> Command line: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe  -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\install\x64-Release"  -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe"  -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe"  -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "E:\computer\boost\cmake"
      1> Working directory: C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\build\x64-Release
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1073 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1075 ] Boost_USE_MULTITHREADED = ON
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1077 ] Boost_USE_STATIC_LIBS = OFF
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1079 ] Boost_USE_STATIC_RUNTIME = OFF
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1081 ] Boost_ADDITIONAL_VERSIONS = 
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1083 ] Boost_NO_SYSTEM_PATHS = 
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1151 ] Declared as CMake or Environmental Variables:
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1153 ]   BOOST_ROOT = C:\boost\boost_1_65_1
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1155 ]   BOOST_INCLUDEDIR = C:\boost\boost_1_65_1
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1157 ]   BOOST_LIBRARYDIR = C:\boost\boost_1_65_1\stage\lib
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1159 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0;...
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1258 ] location of version.hpp: C:/boost/boost_1_65_1/boost/version.hpp
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1282 ] version.hpp reveals boost 1.65.1;...
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1368 ] guessed _boost_COMPILER = -vc141;-vc140
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1378 ] _boost_MULTITHREADED = -mt
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1422 ] _boost_RELEASE_ABI_TAG = -
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1424 ] _boost_DEBUG_ABI_TAG = -gd
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1486 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = C:\boost\boost_1_65_1\stage\lib;C:\boost\boost_1_65_1/lib;...
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1636 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-vc141-mt-1_65_1;boost_filesystem-vc141-mt
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1687 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-vc141-mt-gd-1_65_1;boost_filesystem-vc141-mt-gd
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1636 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_65_1;boost_system-vc141-mt
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1687 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-vc141-mt-gd-1_65_1;boost_system-vc141-mt-gd
      1> -- [ C:/Program Files (x86)/.../FindBoost.cmake:1762 ] Boost_FOUND = 1
      1> -- Boost LIBRARIES: 
      1> CMake Error at C:/Program Files (x86)/.../FindBoost.cmake:1923 (message):
      1>   Unable to find the requested Boost libraries.
      1> 
      1>   Boost version: 1.65.1
      1> 
      1>   Boost include path: C:/boost/boost_1_65_1
      1> 
      1>   Could not find the following Boost libraries:
      1> 
      1>           boost_filesystem
      1> 
      1>   Some (but not all) of the required Boost libraries were found.  You may
      1>   need to install these additional Boost libraries.  Alternatively, set
      1>   BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
      1>   to the location of Boost.
      1> Call Stack (most recent call first):
      1>   CMakeLists.txt(17): (find_package)
      1> 
      1> 
      1> -- Configuring incomplete, errors occurred!
      1> See also "C:/Users/david/CMakeBuilds/94321a3b-9fa8-083f-a86f-e151c3abae79/build/x64-Release/CMakeFiles/CMakeOutput.log".
      1> C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe  -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\david\CMakeBuilds\94321a3b-9fa8-083f-a86f-e151c3abae79\install\x64-Release"  -DCMAKE_CXX_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe"  -DCMAKE_C_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.13.26128/bin/HostX64/x64/cl.exe"  -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\PROFESSIONAL\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "E:\computer\boost\cmake" returned with exit code: 1
      CMake Error at C:/Program Files (x86)/.../FindBoost.cmake:1923 (message):
        Unable to find the requested Boost libraries.
        Boost version: 1.65.1
        Boost include path: C:/boost/boost_1_65_1
        Could not find the following 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:17 (find_package)
      

1 个答案:

答案 0 :(得分:1)

libboost_filesystem-vc141-mt-gd-1_65_1.lib是文件系统库的静态版本(名称以 lib 开头)

在CMake中,您正在搜索动态版本:

set(Boost_USE_STATIC_LIBS       OFF)

这不起作用。现在你必须选择:

  1. OFF切换为ON
  2. 通过以下添加重建boost:
  3. b2 toolset=msvc-14.1 address-model=64 --build-type=complete

    命令--build-type=complete构建所有支持的库变体。只是为了安全起见; - )