是否可以使用某种路径进行 #include

Is it possible to use some sort of path for #include?

本文关键字:#include 路径 可以使 是否      更新时间:2023-10-16

我在文件中有一堆 #include 语句:

#include "/Users/cooper/Desktop/MyLib/graph_api.h"
#include "/Users/cooper/Desktop/MyLib/mst.h"
#include "/Users/cooper/Desktop/MyLib/dfs.h"
#include "/Users/cooper/Desktop/MyLib/bfs.h"
#include "/Users/cooper/Desktop/MyLib/topo_sort.h"
#include "/Users/cooper/Desktop/MyLib/scc.h"
#include "/Users/cooper/Desktop/MyLib/bipartite.h"
#include "/Users/cooper/Desktop/MyLib/dijkstra.h"
#include "/Users/cooper/Desktop/MyLib/union_find.h"
#include "/Users/cooper/Desktop/MyLib/my_string.h"
#include "/Users/cooper/Desktop/MyLib/2d_array.h"

不过,将来可能会发生变化,我将不得不更新一些行。有没有可能有类似的东西

PATH = "/Users/cooper/Desktop/MyLib/
#include PATH + "2d_array.h"

通常,编译器会提供一个选项,您可以在其中添加路径,以便从#include语句中查找头文件。

例如,对于海湾合作委员会添加

-I/Users/cooper/Desktop/MyLib

到编译器命令行。


此选项也可以设置在 IDE 的项目设置中,或作为生成系统中的变量进行设置。