gcc常用參數和環境變量小結

轉自:http://keyknight.blog.163.com/blog/static/366378402007111811412356/

 

本文結合:http://blog.csdn.net/zblue78/archive/2007/02/01/1499717.aspx 看,完美了

 

Command-Line Options
命令行參數


-c
Preprocess, compile, and assemble only (i.e., don't link).
預處理(生成.i,用完刪除)、編譯、(生成.s,用完刪除),彙編(生成.o),不連接(不生成可執行文件)。Btw,貌似很多地方可以用-pipe直接通過管道,不生成臨時文件,加快編譯

-C
Leave comments in when preprocessing.
預處理時不去除註釋(結合其他會留下預處理輸出的參數使用,如-E)

-D name[= definition]
Defines the symbol name.
定義一個標識符(相當於程序裏面寫#define name[= definition],可以結合#ifndef name實現控制功能)

-e name
Start program execution at name.
(對一個Freestanding的程序,比如自己寫的OS)自定義入口函數(常和-ffreestanding -nostartfiles –nostdlib等一起使用)

-E
Preprocess only; output to stdout, unless used with -o.
只預處理,結果輸出到標準輸出,除非用-o指定輸出文件(一般爲*.i)

-ffast-math
Permit faster floating-point arithmetic methods at the cost of accuracy or precision.
浮點數運算的時候以精度換速度(第一個f是flag的意思。C99使用比以前更好數值精確度,當然我們也可以不用。。這個參數定義_ _FAST_MATH_ _這個宏,相當於後面要說的6個浮點相關運算參數的並集,which對我來說長得相當古怪!)

-ffinite-math-only
Disregard infinities and NaN ("not a number") values.
浮點相關運算參數。我沒看懂“Disregard”到底是指丟棄,還是說不檢查就接收。。

-ffreestanding
Compile as a freestanding (not hosted) program.
編譯一個獨立的程序(比如不會去連接crt0.o,“which contains the actual entry point of the executable program”,crt = C Runtime)

-finline-functions, -fno-inline-functions
Enable/disable inline functions.
允許/不允許內聯函數

-fno-math-errno
Disable the errno variable for simple math functions.
浮點相關運算參數。浮點數學函數中出錯了不使用errno這個全局變量?

-fno-trapping-math
Generate "nonstop" floating-point code.
浮點相關運算參數。“Generates "nonstop" code, on the assumption that no math exceptions will be raised that can be handled by the user program.”假設沒有數學操作產生的異常是用戶能處理的,非常拗口。。用國語說就是浮點運算就不產生該有的異常了,反正用戶也處理不了

-frounding-math
Don't disregard the rounding-mode features of the floating-point environment (experimental).
浮點相關運算參數-fno-rounding-math的opposite。使用一些規則來舍入?

-fsignaling-nans
Allow all exceptions raised by signaling NaNs (experimental).
浮點相關運算參數-fno-signaling-nans的opposite。這個singal又拿不準了。。數學參數我放棄了。。

-fsyntax-only
Don't compile or link; just test input for syntax.
只測試輸入語法有效性(比如先找點Warning之類的,不用花時間編譯)

-funroll-loops, -fno-unroll-loops
Enable/disable loop optimization.
對循環做優化(比如把一些小循環的跳轉改成線性的代碼,貌似會使文件增大?)

-funsafe-math-optimizations
Permit optimizations that don't conform to standards and/or don't verify values.
浮點相關運算參數。看名字吧。。。

-fverbose-asm
Include C variable names as comments in assembly language.
在生成的的彙編語言裏面將C變量名加到註釋裏面(結合會留下彙編輸出的參數使用,如-S)

-g[ format]
Compile for debugging.
生成包含特定format調試信息的文件(比如-ggdb,結合GDB來調試。當然debug的會比release的大很多)

-I directory[: directory[...]]
Search for "include" files in the specified path.
指定#include時的查找路徑,多個路徑用冒號隔開
Quote:“
The usual search order for include directories is:
1.    The directory containing the given source file (for filenames in given in quotation marks in an #include directive).
2.    Directories specified by -I options, in command-line order.
3.    Directories specified in the environment variables C_INCLUDE_PATH and CPATH.
4.    The system's default include directories.”

-I-
Distinguish between -Ipath for #include <file> and -Ipath for #include "file".
這個的具體解釋實在拗口了點:
Quote:“
This option divides any -Idirectory options on the command line into two groups. All directories appended to an -I option to the left of -I- are not searched for header files named in angle brackets in an #include directive, such as this one:
#include <stdio.h>

Instead, they are searched only for header files named in quotation marks in the #include directive, thus:
#include "myheader.h"

The second group consists of any directories named in an -I option to the right of -I-. These directories are searched for header files named in any #include directive.

Furthermore, if -I- appears on the command line, then the directory containing the source file is no longer automatically searched first for header files.”

-lbasename
Link with library libbasename.so or libbasename.a.
連接以libbasename爲名的shared object或者archive(類似Windows上.dll和.lib,當然常和-L一起用的。Btw難道gcc調用的庫必須以lib-開頭?)

-L directory[: directory[...]]
Search for library files in the specified path.
指定連接時的查找路徑,多個路徑用冒號隔開

-march= cpu
Intel x86: Generate model-specific code.
爲某個平臺優化,第一個m意思是machine或者model。對於x86體系來說,-mcpu和-mtune是一樣,-march可以爲不同cpu產生優化的代碼,比如-march=athlon-4(具體的cpu abbr.看gcc manual)

-mcpu= cpu
Sparc, ARM, and RS/6000-PowerPC: Generate model-specific code.
Intel x86: Optimize scheduling for the specified CPU model.
爲某個平臺優化,對於x86和非x86體系來說,-m系列參數意義有點不一樣,見前面-march
Quote:“
For several processor types, such as the Sparc, ARM, and RS/6000-PowerPC series, the option -mcpu=cpu generates machine code for the specific CPU type's register set, instruction set, and scheduling behavior. Programs compiled with this option may not run at all on a different model in the same CPU family.”

-mtune= cpu
Optimize scheduling for the specified CPU model.
爲某個平臺優化,這個比-mcpu要“溫和”一點。
Quote:“
The option -mtune=cpu is more tolerant. Code generated with -mtune=cpu uses optimized scheduling parameters for the given CPU model, but adheres to the family's common instructions and registers, so that it should still run on a related model.”

-nostartfiles
Don't link startup code.
Quote:“
On most systems, GCC also links programs by default with initialization routines in object files named crtbegin.o and crtend.o.”

-nostdlib
Don't link with the standard library.
不連接C Stanndard Library

-o file
Direct output to the specified file.
指定輸出文件名。

-O0
Turn off all optimization options.
不優化。

-O, -O1
Perform some optimization without taking much time.
優化

-O2
Perform more optimization, including data flow analysis.
再優化

-O3
Perform still more optimization, including inline function compilation.
優化到底

-Os
Optimize for size.
只在文件大小方面做優化

-p
Link in code to output profiling information.
誰告訴我中文裏面profiling到底怎麼翻譯?性能剖析?“The -p option adds special functions to your program to output profiling information when you run it. The profiling output is saved in a file called mon.out.”

-pedantic
Output warnings on nonstandard usage.
爲非標準用法產生Warning(比如ANSI C不包括但是GUN C擴展的地方,見-std)

-pedantic-errors
Fail on nonstandard usage.
這個比較狠,編寫portable代碼應該用上

-pg
Link in code to output profiling information for gprof.
爲GUN Profiler,gprof輸出profiling information,這次輸出文件叫gmon.out

-s
Strip symbol tables from executable file.
優化參數。在執行文件中去除符號表(執行文件裏面有符號表的話有什麼好處呢?回去複習編譯吧。。-_-)
Quote:“
This makes the finished program file significantly smaller, and is often used in building a production version.

-S
Preprocess and translate into assembly language only.
預處理,編譯,到生成*.s爲止,不彙編。

-save-temps
Save intermediate output files.
留下所有編譯過程中產生的文件:.i、.s、.o

-shared
Create a shared object file for dynamic linking.
生成.so文件,類似dll

-static
Don't link to shared object files.
只靜態連接,就是說生成的文件不會去連接.so文件

-std=iso9899:1990
-std=c89
-ansi
Support ISO/IEC 9899:1990.
都是一樣的。支持ANSI C標準,與標準衝突的擴展被disable(比如GUN的tyepeof操作符,好東西啊。。)

-std=iso9899:199409
Support ISO/IEC 9899:1989 and AMD1.
另一個標準

-std=c99
Support ISO/IEC 9899:1999.
不知道現在對C99的支持做完了沒?

-std=gnu89
Like -ansi, plus GNU extensions (default).
默認-std選項,看名字

-std=gnu99
Like -std=c99, plus GNU extensions.
估計是現在的默認了

-traditional
Support old-style C. Deprecated; supported only with -E.
注意:“supported only with –E”,只在預處理的時候有用

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章