我在C預處理和C編譯之間執行一些源處理。目前我:如何編譯已經用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代碼已經過預處理通過指定被編譯爲c-cpp-output
語言(見this頁-x
)。但它不起作用。我剛剛得到這個:
$ 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]
那麼,這與一個你好的世界,但與我的代碼沒有。讓我看看發生了什麼。 – 2010-01-25 15:00:33
也許試試'gcc -x cpp-output -std = c99 xyz.cppoutput'? – leegent 2010-01-25 15:05:48
在visual studio中是否有類似的選項? – Naveen 2015-11-22 00:00:47