【发布时间】:2015-02-08 01:07:11
【问题描述】:
是否有编译器或预处理器标志会强制 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 ""。有吗?
【问题讨论】:
标签: c gcc header include c-preprocessor