GCC/G+/CLang基本用法
3044 ワード
コンパイラ側のいくつかのコマンド
gcc/g++
一.共通コンパイルコマンドオプション
gccコンパイルプロセス
1.オプションなしでリンクをコンパイル
2.オプション-oステップ4リンク(Linking)
3.オプション-E第一歩前処理(Pre-Processing)
4.オプション-S第2ステップコンパイル(Compiling)
5.オプション-c第3ステップアセンブリ(Assembling)
6.オプションリンクなし
7.オプション-O
二.マルチソースファイルのコンパイル方法
1.複数のファイルを一緒にコンパイル
2.各ソースファイルをそれぞれコンパイルし、コンパイル後に出力されるターゲットファイルへのリンクを作成します.
clang
gcc/g++
一.共通コンパイルコマンドオプション
gcc -Wall test.c -o test
gccコンパイルプロセス
.c ->(-E)->
.i[ ] ->(-S)->
.s( ) ->(-c)->
.o[ ] ->
1.オプションなしでリンクをコンパイル
> : gcc test.c
> : test.c 、 、 。 , a.out。
2.オプション-oステップ4リンク(Linking)
> : gcc test.c -o test
> : test.c 、 、 test。-o 。
3.オプション-E第一歩前処理(Pre-Processing)
> : gcc -E test.c -o test.i
> : test.c test.i 。
4.オプション-S第2ステップコンパイル(Compiling)
> : gcc -S test.i
> : test.i test.s 。
5.オプション-c第3ステップアセンブリ(Assembling)
> : gcc -c test.s
> : test.s test.o 。
6.オプションリンクなし
> : gcc test.o -o test
> : test.o test。
7.オプション-O
> : gcc -O1 test.c -o test
> : 1 。 1~3, , 。
二.マルチソースファイルのコンパイル方法
1.複数のファイルを一緒にコンパイル
> :#gcc testfun.c test.c -o test
> : testfun.c test.c test 。
2.各ソースファイルをそれぞれコンパイルし、コンパイル後に出力されるターゲットファイルへのリンクを作成します.
> :
> gcc -c testfun.c // testfun.c testfun.o
> gcc -c test.c // test.c test.o
> gcc -o testfun.o test.o -o test // testfun.o test.o test
clang
clang --help
clang file.c -fsyntax-only (check for correctness)
clang file.c -S -emit-llvm -o - (print out unoptimized llvm code)
clang file.c -S -emit-llvm -o - -O3
clang file.c -S -O3 -o - (output native machine code)