【问题标题】:C++ CMake cannot find Boost 1.63 (using CLion IDE)C++ CMake 找不到 Boost 1.63(使用 CLion IDE)
【发布时间】:2017-04-09 02:26:05
【问题描述】:

我确实花了 6 个小时在上面,并在互联网上到处查看。

这就是我所做的。我在使用 JetBrain CLion IDE 的 Windows 10 上。直接下载MinGW 5.3,不是通过CodeBlocks。下载 Boost 1.63 并解压。运行bootstrap.bat gccb2.exe toolset=gcc 来构建它。在安装过程中,gcc-mingw-5.3.0 出现了很多次,所以我想它们现在以某种方式链接了。然后出现了一个新文件夹C:/Boost,其中只包含两个文件夹:include 和 lib。

这是我的 CMakeList.txt:

cmake_minimum_required(VERSION 3.7)
project(BoostTest)

set(CMAKE_CXX_STANDARD 11)

set(Boost_INCLUDE_DIR C:/Boost/include)
set(BOOST_LIBRARY_DIR C:/Boost/lib)
find_package(Boost COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

set(SOURCE_FILES main.cpp)
add_executable(BoostTest ${SOURCE_FILES})

由于原始目录(我从下载中解压缩)没有名为includelib 的目录,我想我应该使用安装(或构建)创建的目录。然后我得到这个错误:

CMake Error at D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1169 (file):
  file STRINGS file "C:/Boost/include/boost/version.hpp" cannot be read.
Call Stack (most recent call first):
  CMakeLists.txt:8 (find_package)


CMake Warning at D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:744 (message):
  Imported targets not available for Boost version 0
Call Stack (most recent call first):
  D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost_COMPONENT_DEPENDENCIES)
  D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:8 (find_package)


CMake Warning at D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:744 (message):
  Imported targets not available for Boost version 0
Call Stack (most recent call first):
  D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost_COMPONENT_DEPENDENCIES)
  D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:8 (find_package)


CMake Error at D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1793 (message):
  Unable to find the requested Boost libraries.

  Boost version: 0.0.0

  Boost include path: C:/Boost/include

  Could not find the following Boost libraries:

          boost_system
          boost_filesystem

  No Boost libraries were found.  You may need to 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:8 (find_package)


-- Configuring incomplete, errors occurred!
See also "C:/Workspace_cpp/BoostTest/cmake-build-debug/CMakeFiles/CMakeOutput.log".

你看,CMake 能够以某种方式访问​​这个version.hpp 文件,但无法读取它。我看到很多人发布了同样的问题,但他们的解决方案都没有对我有用。我试图将INCLUDE_DIRLIBRARY_DIR 设置为原始目录,但没有一点帮助。我真的很沮丧。我非常感谢任何帮助。谢谢!

更新: 感谢 oLen 指出!这很有帮助。我已将我的 CMakeList.txt 更新为:

set(BOOST_ROOT C:/Boost)
set(BOOST_INCLUDEDIR C:/Boost/include)
set(BOOST_LIBRARYDIR C:/Boost/lib)
find_package(Boost COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

但是,我收到一条新的错误消息:

"D:\Program Files (x86)\JetBrains\CLion 2017.1\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Workspace_cpp\BoostTest
CMake Warning at D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:744 (message):
  Imported targets not available for Boost version
Call Stack (most recent call first):
  D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:848 (_Boost_COMPONENT_DEPENDENCIES)
  D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1435 (_Boost_MISSING_DEPENDENCIES)
  CMakeLists.txt:9 (find_package)


CMake Error at D:/Program Files (x86)/JetBrains/CLion 2017.1/bin/cmake/share/cmake-3.7/Modules/FindBoost.cmake:1793 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.
Call Stack (most recent call first):
  CMakeLists.txt:9 (find_package)


CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_INCLUDE_DIR (ADVANCED)

我认为它成功定位了目录但无法处理它。我很抱歉一直问,这些错误对我来说完全没有意义。我也可以知道是否应该在使用之前构建 Boost,因为在官方的 Boost Get Started 页面中,它并没有说要构建它。错误消息还希望我set BOOST_INCLUDE_DIR。你能再解释一下吗?非常感谢。

【问题讨论】:

    标签: c++ windows gcc boost cmake


    【解决方案1】:

    您没有设置变量以正确找到 Boost。

    如果您查看FindBoost.cmake,您会看到以下内容:

    # This module reads hints about search locations from variables::
    #
    #   BOOST_ROOT             - Preferred installation prefix
    #    (or BOOSTROOT)
    #   BOOST_INCLUDEDIR       - Preferred include directory e.g. <prefix>/include
    #   BOOST_LIBRARYDIR       - Preferred library directory e.g. <prefix>/lib
    #   Boost_NO_SYSTEM_PATHS  - Set to ON to disable searching in locations not
    #                            specified by these hint variables. Default is OFF.
    #   Boost_ADDITIONAL_VERSIONS
    #                          - List of Boost versions not known to this module
    #                            (Boost install locations may contain the version)
    

    在您的情况下,最简单的解决方案是将BOOST_ROOT 设置为包含libinclude(即C:/Boost)的文件夹,或者使用正确的变量名称BOOST_INCLUDEDIRBOOST_LIBRARYDIR(没有第二个下划线)。

    第二个下划线的变量也存在,但是在搜索Boost的时候是set的。

    【讨论】:

      【解决方案2】:

      研究了几天,安装卸载了无数次,原来我只是看错了一行:

      set(BOOST_INCLUDEDIR C:/boost/include/boost-1_63)
      

      就是这样!天哪。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-05-08
        • 2011-04-18
        • 1970-01-01
        • 2015-10-19
        • 2011-12-26
        • 2022-01-02
        相关资源
        最近更新 更多