Cmake包含目录
Cmake include directories
我有一个这样的文件夹结构:Project/LLibraries/Math,Project/LLibrarys/Math2。
在Project文件夹中,我有main.cpp和CMakeLists.txt,其中包含以下内容:
cmake_minimum_required (VERSION 2.6)
project (CppMain)
add_executable(CppMain main.cpp)
include_directories(${CMAKE_CURRENT_SOURCE_DIR))
在Math文件夹中,我有标题MyVectors.h,在Math2文件夹中我有MyMatrix.h,我想将其包含在main.cpp文件中,其工作方式为:
#include "Libraries/Math/MyVectors.h"
#include "Libraries/Math2/MyMatrices.h"
问题是,标头MyVectors.h也以同样的方式包含标头MyMatrix.h,但链接器找不到它。我可以在CMakeLists中修改什么来解决这个问题?
这似乎是相对路径的经典情况。您这样做是为了将文件包含在main.cpp
中
#include "Libraries/Math/MyVectors.h"
#include "Libraries/Math2/MyMatrices.h"
为了让文件访问父目录,您可以使用../
。MyVectors.h
中应引入以下行:
#include "../Math2/MyMatrices.h"
这意味着什么?当你使用../
时,你的文件MyVectors.h
在Math
文件夹中,它会把你带到Math
的父目录,即Libraries
。从那里你可以简单地按照路径到你需要的目录。
关于另一个问题,我可以在这个答案中找到更多细节:https://stackoverflow.com/a/35910234/2555668
相关文章:
- 在CMake中使用find_package时,是否会显式包含标头
- 如何在 cmake 库中包含 libcurl
- Visual Studio 中的 CMake 项目:如何添加其他包含和库目录?
- CMake 错误"源似乎不包含 CMakeLists.txt",路径/库连接问题
- CMake:我们可以为一组不形成可执行文件或库的特定文件指定包含目录吗?
- CMake 将库包含在另一个库中
- GCC 包含标头(使用"-include")CMake 未检测到的更改
- 以现代 CMake 方式控制包含的库中的构建选项(测试等)
- CMake 错误 - 目标 foo INTERFACE_SOURCES属性包含在源目录中以前缀为前缀的路径
- CMake 导入本地共享库以及如何将其包含在标头中
- CMake 包支持 - 找不到包含和库
- CMake 如何强制third_party库将项目文件包含在当前项目源目录中?
- CMake 包含非 cmake 库的第三方标头
- cmake 可以包含具有头文件和库文件但没有 .cmake 文件的库吗?
- 我怎样才能简单地将opencv 包含在我的项目中与CMake
- 我的项目中某些仅标头文件不能包含使用 CMake 和 Vscode 的"SFML/Graphics.hpp"
- 如何找到 -lm lib 并将其包含在 CMake 中?
- 为什么我无法包含来自 cmake 导出/导入库的头文件
- 如何在 Linux 上将所有第三方运行时依赖项包含在 cmake/cpack 生成的包中
- 将 MySQL 包含在 cmake 中