操作包含文件的搜索路径

Dan*_*ook 3 c gcc include

我的开发环境是这样的,我some_header.h/usr/include/another/directory. /another/directory包含我需要在我的程序包括一些头文件,但我想用some_header.h/usr/include.我用的时候

 gcc ... -I/another/directory
Run Code Online (Sandbox Code Playgroud)

gcc使用/another/directory/some_header.h.如果我使用

 gcc ... -I/usr/include -I/another/directory
Run Code Online (Sandbox Code Playgroud)

gcc做了同样的事情,因为它忽略了,/usr/include因为它是标准搜索路径的一部分,但它在非标准目录包括在之后被搜索-I.

有任何想法吗?

Kar*_*and 6

使用-iquote开关:

使用引号包含另一个/目录中的文件:

#include "another_file.h"
Run Code Online (Sandbox Code Playgroud)

然后用

gcc -iquote /another/include ...
Run Code Online (Sandbox Code Playgroud)

为引用的包含文件添加搜索路径.此开关将添加一个目录,在当前目录之后和-I和系统包含路径之前搜索引用的包含文件.

使用括号(即#include <header.h>)包括其他包含文件.

有关更多信息,请参见此处: 存储包含文件的位置 - Ubuntu Linux,GCC


dmc*_*kee 5

你看过吗-nostdinc

手册说:

-nostdinc
不要在标准系统目录中搜索头文件。仅搜索使用 -I 选项指定的目录(以及当前文件的目录,如果适用)。

当然,这意味着必须指定通常在您确实想要的标准搜索路径上进行的任何内容......