首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++ CMake找不到Boost 1.63 (使用CLion IDE)

C++ CMake找不到Boost 1.63 (使用CLion IDE)
EN

Stack Overflow用户
提问于 2017-04-09 02:26:05
回答 2查看 2.6K关注 0票数 1

我确实花了6个小时在上面,在互联网上到处寻找。

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

这是我的CMakeList.txt:

代码语言:javascript
复制
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的目录,所以我认为应该使用安装(或构建)创建的目录。然后我得到了这个错误:

代码语言:javascript
复制
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更新为:

代码语言:javascript
复制
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})

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

代码语言:javascript
复制
"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开始页面中,它并没有说要构建它。错误消息还希望我使用set BOOST_INCLUDE_DIR。你能多放点光吗?非常感谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-13 07:12:20

经过几天的研究,安装和卸载了很多次,结果发现我只是搞错了一句:

代码语言:javascript
复制
set(BOOST_INCLUDEDIR C:/boost/include/boost-1_63)

就这样!我的天啊。

票数 0
EN

Stack Overflow用户

发布于 2017-04-09 09:11:13

您还没有将变量设置为正确找到Boost。

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

本模块从变量中读取有关搜索位置的提示:## BOOST_ROOT -首选安装前缀#(或BOOSTROOT) # BOOST_INCLUDEDIR -首选目录(例如/include # BOOST_LIBRARYDIR )-首选库目录(例如/lib # Boost_NO_SYSTEM_PATHS )-设置为在这些提示变量未指定的位置禁用搜索。默认是关闭的。# Boost_ADDITIONAL_VERSIONS #-这个模块不知道的Boost版本列表# (Boost安装位置可能包含该版本)

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

带有第二个下划线的变量也存在,但它们是在搜索Boost时设置的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43302392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档