Last Update 2021/03/23
-fsyntax-only
コード上の構文エラーのチェックまでを実行
テスト概要
エラー無しのコードで実行した場合
-fsyntax-onlyオプション有無による出力内容を比較
エラーが発生するコードで実行した場合
-fsyntax-onlyオプション有無による出力内容を比較
実行環境
GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1
GNU C Library 2.28
GNU Binutils 2.31.1
コード例・出力内容中の表記
・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
使用ファイル
main.c
/* -fsyntax-only オプション動作確認用ソースファイル */
#include <stdio.h>
int main(void)
{
float f;
f = 2.22;
printf("f = %f\n", f);
return 0;
}
main_error.c
/* -fsyntax-only オプション動作確認用ソースファイル */
#include <stdio.h>
int main(void)
{
float f;
f = 2.22;
prrintf("f = %f\n", f);
return 0;
}
エラー無しのコードで-fsyntax-onlyオプション無しで実行
$ gcc -v main.c
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main.c ... -o /tmp/ccfC7CQx.s
︙ コンパイル
as -v --64 -o /tmp/ccNdmIK8.o /tmp/ccfC7CQx.s
︙ アセンブル
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ...
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
リンク
$ 処理終了
エラー無しのコードで-fsyntax-onlyオプション有りで実行
$ gcc -v -fsyntax-only main.c
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main.c ... -fsyntax-only -o /dev/null
︙ コンパイル(/dev/nullへ出力 ---> 出力内容を破棄)
COLLECT_GCC_OPTIONS='-v' '-fsyntax-only' '-mtune=generic' '-march=x86-64'
$ 処理終了(コンパイルのみ)
エラーが発生するコードで-fsyntax-onlyオプション無しで実行
$ gcc -v main_error.c
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main_error.c ... -o /tmp/ccmJ8Vin.s
︙ コンパイル
main_error.c: In function ‘main’: 構文チェック
main_error.c:10:2: warning: implicit declaration of function ‘prrintf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
prrintf("f = %f\n", f);
^~~~~~~
printf
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
as -v --64 -o /tmp/ccg7WWBz.o /tmp/ccmJ8Vin.s
︙ アセンブル
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/collect2 ... <--- リンク
/usr/bin/ld: /tmp/ccg7WWBz.o: in function `main':
main_error.c:(.text+0x25): undefined reference to `prrintf'
collect2: error: ld returned 1 exit status
$ エラー発生・終了
エラーが発生するコードで-fsyntax-onlyオプション有りで実行
$ gcc -v -fsyntax-only main_error.c
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main_error.c ... -fsyntax-only -o /dev/null
︙ コンパイル(/dev/nullへ出力 ---> 出力内容を破棄)
main_error.c: In function ‘main’: 構文チェック
main_error.c:10:2: warning: implicit declaration of function ‘prrintf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
prrintf("f = %f\n", f);
^~~~~~~
printf
︙
COLLECT_GCC_OPTIONS='-v' '-fsyntax-only' '-mtune=generic' '-march=x86-64'
$ 処理終了(コンパイルのみ)