是否有编译器或预处理程序标志会强制gcc像#include <x.h>
一样处理#include "x.h"
?我有一堆生成的代码,使用#include <>
表示当前目录中的文件,gcc报告这些文件没有这样的文件或目录。我正在寻找一种不涉及编辑代码的解决方法。
编辑:-I.
没有这样做。假设我有以下文件:
富/ foo.h中:
#include <foo2.h>
富/ 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 ""
。是否存在?
答案 0 :(得分:6)
是的,您可以将开关-I .
传递给编译器,将当前目录添加到包含搜索路径。
答案 1 :(得分:3)
-I-选项可能会对您有所帮助。来自gcc的手册页:
-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.