【发布时间】:2020-04-12 17:28:36
【问题描述】:
我是 C++ 新手,想在我的项目中包含 boost 库(特别是需要构建的文件系统部分)。我尝试了其他 stackoverflow 用户的许多解决方案,但他们根本没有帮助我。我正在将 CLion 与 CMake 一起使用。 main.cpp 正在调用 modules/ 文件夹中的其他 .cpp 文件。
文件结构:
ProjectName
>boost
>lots of folders and .hpp files
>cmake-build-debug
>modules
encryption.cpp
encryption.h
output.cpp
output.h
CMakeLists.txt
main.cpp
当您下载并解压时,boost 文件夹不包含整个 boost。我在我的项目中拖动了 boost_1_72_0 内的 boost 文件夹(只是为了让你知道里面没有 libs 文件夹等)
CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(ProjectName)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
set(SOURCE_FILES
main.cpp
modules/encryption.cpp modules/encryption.h modules/output.cpp modules/output.h
)
set(Boost_ARCHITECTURE -x64)
set(BOOST_ROOT boost/)
set(Boost_INCLUDE_DIRS boost/filesystem)
find_package(Boost COMPONENTS system filesystem REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(ProjectName ${SOURCE_FILES})
target_link_libraries(ProjectName ${Boost_LIBRARIES})
输出.cpp
// some includes //
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include "../boost/filesystem.hpp"
// some code //
错误信息:
CMake Error at C:/Program Files/JetBrains/CLion 2019.1.4/bin/cmake/win/share/cmake-3.14/Modules/FindBoost.cmake:2147 (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:15 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/Users/username/Desktop/C++/ProjectName/cmake-build-debug/CMakeFiles/CMakeOutput.log".
mingw32-make.exe: *** [cmake_check_build_system] Error 1
Makefile:235: recipe for target 'cmake_check_build_system' failed
我知道它基本上是在告诉我必须做什么,但我不知道 boost 的“根目录”、“包含 Boost 的标头”的目录以及如何将所有内容放在一起的确切含义。
非常感谢!
【问题讨论】: