有没有一种方法可以让gcc将#include <>视为#include ""?

3
有没有编译器或预处理器标志,可以强制gcc将#include <x.h>视为#include "x.h"? 我有一堆生成的代码使用#include <>引用当前目录中的文件,但是gcc报告这些文件不存在。 我正在寻找一种解决方法,不涉及编辑代码。
编辑: -I。无法解决此问题。 假设我有以下文件:

foo/foo.h:

#include <foo2.h>

foo/foo2.h:

#define FOO 12345

xyz/xyz.c

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

int main(void)
{
    printf("FOO is %d\n", FOO);
    return 0;
}

如果我在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.)

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

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

#include "foo2.h"

然后编译就可以了。我知道我可以在命令行中添加-I../foo,但我正在寻找一种更通用的方法来将#include <>视为#include ""。是否存在这样的方法?

2个回答

6

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


3
-I- 选项可能会对你有所帮助。以下是来自 gcc 的 man 页面的说明:
   -I- Split the include path.  Any directories specified with -I options
       before -I- are searched only for headers requested with
       "#include "file""; they are not searched for "#include <file>".  If
       additional directories are specified with -I options after the -I-,
       those directories are searched for all #include directives.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接