include_directories()
时间: 2023-12-29 12:58:27 浏览: 26
include_directories() 函数是 CMake 构建系统中的一个指令,用于指定包含的目录。它可以用来告诉编译器在哪些目录中查找头文件。
该函数的语法如下:
```
include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 ...])
```
其中,可以指定多个目录,用空格分隔。AFTER 和 BEFORE 参数用于确定目录的搜索顺序,SYSTEM 参数表示该目录为系统目录。
例如,要将 `/path/to/include` 目录添加到编译器的头文件搜索路径中,可以使用以下语句:
```cmake
include_directories(/path/to/include)
```
这样,在编译时,编译器就能够找到位于 `/path/to/include` 目录下的头文件。
相关问题
include_directories
`include_directories` 是 CMake 的一个指令,用于向 CMake 告知需要包含的头文件目录。
例如,假设我们有一个头文件 `foo.h`,它位于路径 `/path/to/foo` 中。我们可以在 CMakeLists.txt 文件中使用 `include_directories` 指令来添加这个头文件目录:
```
include_directories(/path/to/foo)
```
这将告诉 CMake 在编译时需要包含 `/path/to/foo` 目录下的头文件。
如果有多个头文件目录需要添加,可以连续多次调用 `include_directories` 指令,例如:
```
include_directories(/path/to/foo)
include_directories(/path/to/bar)
```
这样就告诉 CMake 需要包含 `/path/to/foo` 和 `/path/to/bar` 两个目录下的头文件。
include_directories target_include_directories
include_directories 和 target_include_directories 都是 CMake 中用来添加头文件搜索路径的命令。
include_directories 是一个全局命令,用于将指定的目录添加到整个项目的头文件搜索路径中。这意味着在项目的任何地方都可以使用这些头文件,而不需要显式地指定路径。
target_include_directories 则是一个针对特定目标的命令,用于将指定的目录添加到特定目标的头文件搜索路径中。这意味着只有特定目标可以使用这些头文件。
两个命令的用法类似,都需要指定目录路径作为参数。例如:
```cmake
include_directories(path/to/directory)
```
```cmake
target_include_directories(my_target PUBLIC path/to/directory)
```
其中,include_directories 可以在 CMakeLists.txt 的任何位置使用,而 target_include_directories 则需要在定义目标之后使用。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)