将自定义路径添加到 gcc 命令

Adding custom path to gcc command

我知道已经有一些关于此的帖子,但我似乎无法正确理解。

我正在使用 geany 和 gcc 开发一个共享项目。文件结构如下所示:

`/Documents/.../project/ main directory of project with makefile`
`/Documents/.../project/src here are some sourcefiles and headers`
`/Documents/.../project/src/extended here are some other source and header files`
`/Documents/.../project/src/tools other header and source files`

现在假设我正在处理 /tools 中的一个源文件,其中包括来自 extened with #include"/extended/some_header.h" 因为我的 makefile 配置为从 /src 搜索文件。但是,当我尝试编译我现在正在处理的文件时(通过使用仅调用 gcc 的 geany 编译选项)我显然无法编译它,因为它在 /src 文件夹中找不到 /extended/some_header.h。我试过添加 -iquotes/Documents/.../project/src 到 geany 的 gcc 调用,但它也不起作用。

-I 标志告诉 gcc 编译器应该在哪里寻找 header 文件。将 -Idir 传递给编译器会将 dir 路径附加到搜索列表的头部,有效地使该路径的优先级高于先前(或系统)定义的路径。至于源路径 - gcc 本身没有这样的选项。传递给编译器的每个源文件都必须有它的路径(绝对或相对)。为了解决这个问题,可以提供 Makefile,定义要编译的文件列表。