2017-04-09 117 views
1

我从字面上花了6个小时,并在互联网上无处不在。C++ CMake无法找到升压1.63(使用CLion IDE)

这是我所做的。我在使用JetBrain CLion IDE的Windows 10上。直接下载MinGW 5.3,而不是通过CodeBlocks。 Downloaded 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入门页面中,它并没有说要构建它。错误信息也要我set BOOST_INCLUDE_DIR。你能否摆脱一些光线?非常感谢。

回答

0

研究了几天,安装和卸载吨次之后,事实证明,我只是弄错一行:

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

这就是它!哦,我的上帝。

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时,它们是设置为