【发布时间】:2010-01-25 14:44:38
【问题描述】:
我正在 C 预处理和 C 编译之间执行一些源代码处理。目前我:
-
gcc -E file.c > preprocessed_file.c. - 为
preprocessed_file.c做更多的事情。 - 使用
preprocessed_file.c继续编译。
如果您尝试编译 preprocessed_file.c,就像它是普通 C(第 3 步)一样,您会得到很多以下内容:
/usr/include/stdio.h:257: error: redefinition of parameter ‘restrict’
/usr/include/stdio.h:257: error: previous definition of ‘restrict’ was here
/usr/include/stdio.h:258: error: conflicting types for ‘restrict’
/usr/include/stdio.h:258: error: previous definition of ‘restrict’ was here
/usr/include/stdio.h:260: error: conflicting types for ‘restrict’
[...]
这只是在file.c 中使用#include <stdio.h>。幸运的是,有一个选项可以告诉 GCC 它正在通过将要编译的语言指定为 c-cpp-output(参见 this 页面上的 -x)来预处理已经预处理的 C 代码。但它不起作用。我只是得到这个:
$ gcc -x c-cpp-output -std=c99 bar.c
i686-apple-darwin9-gcc-4.0.1: language c-cpp-output not recognized
i686-apple-darwin9-gcc-4.0.1: language c-cpp-output not recognized
ld warning: in bar.c, file is not of required architecture
Undefined symbols:
"_main", referenced from:
start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
在新版本的 GCC 上的响应完全相同:
$ gcc-mp-4.4 -x c-cpp-output -std=c99 bar.c
[same error stuff comes here]
【问题讨论】:
标签: c compilation