如何编译已经用GCC预处理的C代码? [英] How can I compile C code that has already been C pre-processed with GCC?

查看:240
本文介绍了如何编译已经用GCC预处理的C代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C预处理和C编译之间执行一些源处理。目前I:


  1. gcc -E file.c> preprocessed_file.c

  2. preprocessed_file.c 执行更多操作。

  3. 使用 preprocessed_file.c 继续编译。

尝试编译 preprocessed_file.c ,如果它是正常的C(步骤3),你会得到以下很多:

  /usr/include/stdio.h:257:error:redefinition的参数'restrict'
/usr/include/stdio.h:257:error:previous definition 'restrict'在这里
/usr/include/stdio.h:258:error:'restrict'的冲突类型
/usr/include/stdio.h:258:error:以前的' restrict'is here
/usr/include/stdio.h:260:error:'restrict'的冲突类型
[...]
中使用 #include< stdio.h> 。幸运的是,有一个选项告诉GCC它通过指定正在编译为 c-cpp-output 的语言已经预处理的C代码执行操作(参见 -x 页)。但它不工作。我只需要这样:

  $ gcc -x c-cpp-output -std = c99 bar.c 
i686 -apple-darwin9-gcc-4.0.1:语言c-cpp输出无法识别
i686-apple-darwin9-gcc-4.0.1:语言c-cpp输出无法识别
ld警告:在bar.c中,文件不是必需的架构
未定义的符号:
_main,引用自:
start in crt1.10.5.o
ld:symbol(s)找不到
collect2:ld退回1退出状态

版本的GCC:

  $ gcc-mp-4.4 -x c-cpp-output -std = c99 bar.c 
[same error stuff here]


解决方案

在GCC文档中输入错误 - 请尝试'-x cpp-output'。

  gcc -E helloworld.c& cppout 
gcc -x cpp-output cppout -o hw
./hw
你好,世界!


I'm performing some source processing between C preprocessing and C compilation. At the moment I:

  1. gcc -E file.c > preprocessed_file.c.
  2. Do more stuff to preprocessed_file.c.
  3. Continue the compilation with preprocessed_file.c.

If you attempt to compile preprocessed_file.c as you would if it was normal C (step 3) you get lots of the following:

/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’
[...]

And that's just using #include <stdio.h> in file.c. Fortunately there's an option to tell GCC it's acting on C code that has already been preprocessed by specifying the language that is being compiled as c-cpp-output (see -x on this page). But it doesn't work. I just get this:

$ 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

And exactly the same response with a newer version of GCC:

$ gcc-mp-4.4 -x c-cpp-output -std=c99 bar.c
[same error stuff comes here]

解决方案

Looks like a typo in the GCC docs - try '-x cpp-output' instead.

gcc -E helloworld.c > cppout
gcc -x cpp-output cppout -o hw
./hw
Hello, world!

这篇关于如何编译已经用GCC预处理的C代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆