gcc常用参数和环境变量小结

来源:互联网 发布:淘宝店铺标题优化 编辑:程序博客网 时间:2024/05/17 07:28

转自: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”,只在预处理的时候有用

原创粉丝点击