有没有办法让gcc像#include一样对待#include <>?

cra*_*535 3 c gcc header include c-preprocessor

是否有一个编译器或预处理器标志会强制gcc #include <x.h>像它一样对待#include "x.h"?我有一堆生成的代码#include <>用于当前目录中的文件,gcc报告这些文件没有这样的文件或目录.我正在寻找一种不涉及编辑代码的解决方法.

编辑:-I.不这样做.假设我有以下文件:

富/ foo.h中:

#include <foo2.h>
Run Code Online (Sandbox Code Playgroud)

富/ foo2.h:

#define FOO 12345
Run Code Online (Sandbox Code Playgroud)

XYZ/xyz.c

#include <stdio.h>
#include "foo/foo2.h"

int main(void)
{
    printf("FOO is %d\n", FOO);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果在xyz我编译的目录中,gcc -o xyz I.. xyz.c编译失败:

In file included from xyz.c:2:
../foo/foo.h:1:18: error: foo2.h: No such file or directory
xyz.c: In function ‘main’:
xyz.c:6: error: ‘FOO’ undeclared (first use in this function)
xyz.c:6: error: (Each undeclared identifier is reported only once
xyz.c:6: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)

添加-I.不会改变任何东西.

但是,如果我将foo/foo.h更改为:

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

然后编译工作.我知道我可以添加-I../foo到我的命令行,但我一直在寻找一种更通用的方法来治疗#include <>#include "".有人存在吗?

Gre*_*ill 6

是的,您可以将开关传递-I .给编译器,以将当前目录添加到包含搜索路径.