CMakelist.txt 将外部 headers 和文件包含在文件夹中(boost 中的 odeint)

CMakelist.txt to include external headers and files in a folder (odeint in boost)

我下载了一个 zip 文件来解决 ODE(boost 中的 odeint),其中包含 headers 和我的 C++ 项目的文件。可以不下载整个boost包直接使用吗?

我的问题是如何使用它。

我在 CMakeLists.txt 文件中添加了一行(如下所示),我能够找到关键 header 文件 odeint.hpp。但是 odeint.hpp 包含其他 header 文件,例如子目录中的 config.hpp(如图所示)。现在编译器找不到其他 header 文件,例如 config.hpp 等,我该怎么办?

(我下载的包来自http://headmyshoulder.github.io/odeint-v2/downloads.html求解ODEs。)

cmake_minimum_required(VERSION 3.5)
project(myProjects)

# I added this line below
include_directories("D:/myProjects/odeint/include")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp test.h test.cpp)
add_executable(myProjects ${SOURCE_FILES})

您还需要 boost 库。我建议只使用 boost 库并从那里使用 odeint。

只需下载并解压即可。然后,您可以轻松使用 CMake。只需添加

set(BOOST_ROOT "/path/to/boost")
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})

给你的CMakeLists.txt