gccのコンパイラオプション
RSSリーダーでチェキしてたら、面白そうなトピックを見つけた。
- Using the GNU Compiler Collection LG #120
http://linuxgazette.net/120/vinayak.html - Using the GNU Compiler Collection (Part2) LG #121
http://linuxgazette.net/121/hegde.html
初めて知ったオプションが結構ある。
幾つかは知っていたが、↓は初見だった。
- "-pg"でプロファイルできる
- "-time"でコンパイル時間を計測できる
- "-v"でコンパイルの内部過程を見られる
- "-E"でプリプロセッサの内部過程を見られる
- "-M"でMakefile用の依存関係を出力する
そういや、Interface誌 で GCCの連載講座があったよな。もう一度復習すべぇか。
"-pg"でプロファイルできる
main関数から test関数を適当に呼び出すコードがあると思いねぇ。
$ gcc -pg hoge.c $ gprof a.exe Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls Ts/call Ts/call name 100.00 0.01 0.01 main 0.00 0.01 0.00 10 0.00 0.00 test ... granularity: each sample hit covers 4 byte(s) for 100.00% of 0.01 seconds index % time self children called name <spontaneous> [1] 100.0 0.01 0.00 main [1] 0.00 0.00 10/10 test [4] ----------------------------------------------- 0.00 0.00 10/10 main [1] [4] 0.0 0.00 0.00 10 test [4] ...
"-time"でコンパイル時間を計測できる
$ gcc -time hoge.c # cc1 0.12 0.09 # as 0.03 0.03 # collect2 0.12 0.33
"-v"でコンパイルの内部過程を見られる
$ gcc -v hoge.c /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs から spec を読み込み中 コンフィグオプション: /gcc/gcc-3.4.4/ ... 存在しないディレクトリ "/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/include" を無視します 重複したディレクトリ "/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/lib/../../include/w32api" を無視します #include "..." の探索はここから始まります: #include <...> の探索はここから始まります: /usr/local/include /usr/lib/gcc/i686-pc-cygwin/3.4.4/include /usr/include /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../include/w32api 探索リストの終わり ...
"-E"でプリプロセッサの内部過程を見られる
$ gcc -E hoge.c # 1 "hoge.c" # 1 "<built-in>" # 1 "<\203R\203}\203\223\203h\203\211\203C\203\223>" # 1 "hoge.c" # 1 "/usr/include/stdio.h" 1 3 4 # 29 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/_ansi.h" 1 3 4 # 15 "/usr/include/_ansi.h" 3 4 # 1 "/usr/include/newlib.h" 1 3 4 # 16 "/usr/include/_ansi.h" 2 3 4 # 1 "/usr/include/sys/config.h" 1 3 4 ...
"-M"でMakefile用の依存関係を出力する
$ gcc -M hoge.c hoge.o: hoge.c /usr/include/stdio.h /usr/include/_ansi.h \ /usr/include/newlib.h /usr/include/sys/config.h \ /usr/include/machine/ieeefp.h /usr/include/cygwin/config.h \ /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stddef.h \ /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stdarg.h \ /usr/include/sys/reent.h /usr/include/_ansi.h /usr/include/sys/_types.h \ /usr/include/sys/lock.h /usr/include/sys/types.h \ /usr/include/machine/_types.h /usr/include/machine/types.h \ /usr/include/sys/features.h /usr/include/cygwin/types.h \ /usr/include/sys/sysmacros.h /usr/include/stdint.h \ /usr/include/sys/stdio.h