在 CMake 中找不到带有'include_directories'的标头
Cannot find a header with 'include_directories' in CMake
这是C 项目的文件夹层次结构:
1. FolderA
1. file1.h/cpp
2. CMakeLists.txt (CmakeA)
2. FolderB
1. file2.h/cpp
2. CMakeLists.txt (CmakeB)
3. main.cpp
4. CMakeLists.txt (CmakeAll)
cmakea:
file(GLOB FolderA_FILES *.cpp *.h *.hpp)
# add component
add_library(FolderA ${FolderA_FILES})
include_directories(../FolderB)
target_link_libraries(FolderA FolderB)
cmakeb:
file(GLOB FolderB_FILES *.cpp *.h *.hpp)
# add component
add_library(FolderB ${FolderB_FILES})
cmakeall:
cmake_minimum_required(VERSION 2.8)
#add smirk dependency
set(Smirk_DIR /usr/local CACHE PATH "Directory where Smirk has been installed (e.g. /usr/local).")
include(${Smirk_DIR}/cmake/smirk.cmake)
smirk_project(operatingTableProject)
file(GLOB smirk_operatingTableProject_FILES *.cpp *.h *.hpp)
add_executable(smirk_operatingTableProject ${smirk_operatingTableProject_FILES})
# install directives
install(
TARGETS smirk_operatingTableProject
RUNTIME DESTINATION bin
)
#add FolderB dependency
add_subdirectory(FolderB)
target_link_libraries(smirk_operatingTableProject FolderB)
#add FolderA dependency
add_subdirectory(FolderA)
target_link_libraries(smirk_operatingTableProject FolderA)
在file1.h
中,我包括file2.h
。问题是我在 main.cpp
FolderA/file1.h
中包含在哪里,我都会得到一个汇编问题:
file2.h: No such file or directory (in file1.h)
但是,如果我在main.cpp
中评论包含的内容,则可以使用。另外,如果我在file1.cpp
中包括file2.h
,它的工作原理是,主要问题是我在其他子目录中的另一个标头文件中包含一个子目录中的标题文件,其中一个包含在主文件中。
任何帮助将不胜感激。
命令 include_directories
仅在 local 范围内影响:在 FolderA
中发出它会影响仅在FolderA
库的汇编时。您需要在编译main.cpp
的顶级CMakeLists.txt
中发出该命令。
另外,您可以在 FolderA
中使用 public 选项使用命令target_include_directories:
target_include_directories(FolderA PUBLIC ../FolderB)
因此,包括目录将传播到与该库链接的任何目标。
相关文章:
- 既然存在危险,为什么项目要使用-I include开关
- 有充分的理由在h文件中使用include保护而不是cpp文件吗
- 如何将更多文件夹添加到c++include路径
- 什么是"#include <boost/functional/hash.hpp> "?
- 对于MacOS上的G++,如何添加默认的include目录/usr/local/include和默认的库搜索路径/usr
- C++包含来自 #include "DevEngine/Core.h" 的错误
- <filesystem> 在 clang 6 和 10 上 #include 错误
- 在 void 函数中使用 #include 变量C++
- N-API include an .so or dll
- 允许哪些令牌作为 #include 的参数?
- GCC 包含标头(使用"-include")CMake 未检测到的更改
- WebAssembly include OpenCV
- 如何在 c++ 中正确指定 #include 路径以使程序可移植
- 修改生成文件以简化框架 #include 路径
- VS2015/VC++ 在新类模板中禁用默认 #include "stdafx.h"
- macOS 致命错误:sys/_types/_int8_t.h:没有此类文件或目录 #include < sys/_types/_int8_t.h>
- #include < conio.h> 和 getch() 方法之间的关系是什么?
- 如何将构建的C++库安装到 /usr/include?
- 包含一批库和目录路径以"Include Additional Directories"视觉C++的任意方法
- 我如何知道 Ubuntu 11.04 中 gcc、g++/c++ 的"default include directories"、"default link directories"和"default