我真的花了6个小时在网上,并在互联网上随处可见。
这就是我所做的。我在使用JetBrain CLion IDE的Windows 10上。直接下载MinGW 5.3,而不是通过CodeBlocks。下载Boost 1.63并解压缩。跑bootstrap.bat gcc
和b2.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})
由于原始目录(我从下载中解压缩)没有名为include
和lib
的目录,我想我应该使用安装(或构建)创建的目录。然后我收到了这个错误:
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_DIR
和LIBRARY_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
。你可以请更多的光吗?非常感谢你。
答案 0 :(得分: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
设置为包含lib
和include
(即C:/Boost
)的文件夹,或使用正确的变量名称{ {1}}和BOOST_INCLUDEDIR
(没有第二个下划线)。
第二个下划线的变量也存在,但在搜索Boost时它们是 set 。
答案 1 :(得分:0)
经过几天的研究,安装和卸载了很多次,事实证明我只是误解了一行:
set(BOOST_INCLUDEDIR C:/boost/include/boost-1_63)
就是这样!我的上帝啊。