Last Update 2020/09/20
-x cpp-output
コンパイラへ供給するファイルの言語を明示的に指定
cpp-output : プリプロセスを必要としないCソースファイル
cpp-output : プリプロセスを必要としないCソースファイル
テスト概要
言語指定オプション「-x cpp-output」によるCソースファイル(プリプロセッサ命令記述有り)のコンパイル
FAIL
プリプロセッサ命令記述部分でエラーが発生・停止
言語指定オプション「-x cpp-output」によるプリプロセス実行済みのCソースファイルのコンパイル
PASS
コンパイル終了・実行ファイル生成
実行環境
GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1
GNU C Library 2.28
GNU Binutils 2.31.1
コード例・出力内容中の表記
・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
使用ファイル
各例共通
sample.c
/* -x オプション動作確認用ソースファイル */
#include <stdio.h>
int main(void)
{
printf("-x オプション動作確認用ソースファイル\n");
return 0;
}
言語指定オプション「-x cpp-output」によるCソースファイルのコンパイル
コンパイル実行結果
$ gcc -v -x cpp-output sample.c
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -fpreprocessed sample.c ...
︙ ^^^ sample.cのコンパイル
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 84637943c330ccfe91c8483610cbfda9
sample.c:3:1: error: stray ‘#’ in program
#include <stdio.h>
^
sample.c:3:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
#include <stdio.h>
^
$ プリプロセッサ記述部分でエラーが発生・停止
言語指定オプション「-x cpp-output」によるプリプロセス実行済みのCソースファイルのコンパイル
sample_c.c 既にプリプロセスを実行済みのファイル
# 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"
# 1 "/usr/include/stdio.h" 1 3 4
# 27 "/usr/include/stdio.h" 3 4
# 1 "/usr/include/bits/libc-header-start.h" 1 3 4
# 33 "/usr/include/bits/libc-header-start.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
︙
extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 864 "/usr/include/stdio.h" 3 4
extern int __uflow (FILE *);
extern int __overflow (FILE *, int);
# 879 "/usr/include/stdio.h" 3 4
# 4 "sample.c" 2
# 5 "sample.c"
int main(void)
{
printf("-x オプション動作確認用ソースファイル\n");
return 0;
}
コンパイル結果
$ ls -l
total 20
-rw-r--r-- 1 ****** ******** 190 *** ** **:** sample.c
-rw-r--r-- 1 ****** ******** 15690 *** ** **:** sample_c.c
$ gcc -v -x cpp-output sample_c.c
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -fpreprocessed sample_c.c ...
︙ ^^^ sample_c.cのコンパイル
as -v --64 -o /tmp/ccCrZIdL.o /tmp/cc9E9ETR.s
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... リンク
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
$ ls -l 処理正常終了
total 40
-rwxr-xr-x 1 ****** ******** 18328 *** ** **:** a.out <--- 実行ファイル
-rw-r--r-- 1 ****** ******** 190 *** ** **:** sample.c
-rw-r--r-- 1 ****** ******** 15690 *** ** **:** sample_c.c
$ ./a.out
-x オプション動作確認用ソースファイル
$