Loose-Info.com
Last Update 2021/12/14
TOP - 各種テスト - gcc - -fpreprocessed オプション

-fpreprocessed
処理対象ファイルの前処理済みである場合に使用

テスト概要

その1
-fpreprocessedオプションを使用して前処理済みのファイル(拡張子 .i)をコンパイル

その2
-fpreprocessedオプションを使用して前処理済みのファイル(拡張子 .aaa)をコンパイル

その3
-fpreprocessedオプションと-xオプションを使用して前処理済みのファイル(拡張子 .aaa)をコンパイル

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


コード例・出力内容中の表記

・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。

使用ファイル

sample.c
#define SAMPLE 0 int main(void) { /* コメント */ return SAMPLE; }

sample.i
# 1 "sample.c" # 1 "<built-in>" # 1 "<command-line>" # 31 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 32 "<command-line>" 2 # 1 "sample.c" int main(void) { return 0; }
sample.i 生成手順
$ ls -l total 4 -rw-r--r-- 1 ****** ******** 75 *** ** **:** sample.c $ gcc -v -E sample.c > sample.i Using built-in specs. /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -E -quiet -v sample.c -mtune=generic -march=x86-64 COLLECT_GCC_OPTIONS='-v' '-E' '-mtune=generic' '-march=x86-64' $ ls -l total 8 -rw-r--r-- 1 ****** ******** 75 *** ** **:** sample.c -rw-r--r-- 1 ****** ******** 187 *** ** **:** sample.i $

その1

-fpreprocessedオプションを使用して前処理済みのファイル(拡張子 .i)をコンパイル
$ ls -l total 8 -rw-r--r-- 1 ****** ******** 75 *** ** **:** sample.c -rw-r--r-- 1 ****** ******** 187 *** ** **:** sample.i $ gcc -v -fpreprocessed sample.i Using built-in specs. /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -fpreprocessed sample.i -quiet -dumpbase sample.i ... as -v --64 -o /tmp/ccp7m7Ho.o /tmp/ccKlrAFP.s /usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... COLLECT_GCC_OPTIONS='-v' '-fpreprocessed' '-mtune=generic' '-march=x86-64' $ ls -l total 28 -rwxr-xr-x 1 ****** ******** 18088 *** ** **:** a.out -rw-r--r-- 1 ****** ******** 75 *** ** **:** sample.c -rw-r--r-- 1 ****** ******** 187 *** ** **:** sample.i $ コンパイル完了。実行ファイル生成

その2

-fpreprocessedオプションを使用して前処理済みのファイル(拡張子 .aaa)をコンパイル
$ mv -v sample.i sample.aaa 「sample.i」の拡張子を.aaaに変更 renamed 'sample.i' -> 'sample.aaa' $ ls -l total 8 -rw-r--r-- 1 ****** ******** 187 *** ** **:** sample.aaa -rw-r--r-- 1 ****** ******** 75 *** ** **:** sample.c $ gcc -fpreprocessed sample.aaa sample.aaa: file not recognized: file format not recognized collect2: error: ld returned 1 exit status $ 拡張子の変更によりファイルフォーマットの認識エラーが発生

その3

-fpreprocessedオプションと-xオプションを使用して前処理済みのファイル(拡張子 .aaa)をコンパイル
$ gcc -fpreprocessed -x cpp-output sample.aaa $ ls -l total 28 -rwxr-xr-x 1 ****** ******** 18088 *** ** **:** a.out -rw-r--r-- 1 ****** ******** 187 *** ** **:** sample.aaa -rw-r--r-- 1 ****** ******** 75 *** ** **:** sample.c $ -xオプションで「プリプロセスを必要としないCソースファイル」を明示的に指定 拡張子「.i」以外のファイルでもエラー無し