是否可以为#include使用某种路径?

ale*_*per 1 c++

我在文件中有一堆#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"
Run Code Online (Sandbox Code Playgroud)

但是,它可能会在未来发生变化,我将不得不更新许多行.有没有可能有类似的东西

PATH = "/Users/cooper/Desktop/MyLib/
#include PATH + "2d_array.h"
Run Code Online (Sandbox Code Playgroud)

πάν*_*ῥεῖ 9

通常,您的编译器提供了一个选项,您可以在其中添加用于从#include语句中查找头文件的pathes .

例如GCC添加

-I/Users/cooper/Desktop/MyLib
Run Code Online (Sandbox Code Playgroud)

到您的编译器命令行.


此选项也可以在IDE的项目设置中设置,或者作为构建系统中的变量设置.