- 论坛徽章:
- 0
|
Command-Line Options命令行参数(in alphabet,整理自《C In A Nutshell》1e,Section18.9,加点自己的理解)-cPreprocess, compile, and assemble only (i.e., don't link).预处理(生成.i,用完删除)、编译、(生成.s,用完删除),汇编(生成.o),不连接(不生成可执行文件)。Btw,貌似很多地方可以用-pipe直接通过管道,不生成临时文件,加快编译-CLeave comments in when preprocessing.预处理时不去除注释(结合其他会留下预处理输出的参数使用,如-E)-D name[= definition]Defines the symbol name.定义一个标识符(相当于程序里面写#define name[= definition],可以结合#ifndef name实现控制功能)-e nameStart program execution at name.(对一个Freestanding的程序,比如自己写的OS)自定义入口函数(常和-ffreestanding -nostartfiles –nostdlib等一起使用)-EPreprocess only; output to stdout, unless used with -o.只预处理,结果输出到标准输出,除非用-o指定输出文件(一般为*.i)-ffast-mathPermit faster floating-point arithmetic methods at the cost of accuracy or precision.浮点数运算的时候以精度换速度(第一个f是flag的意思。C99使用比以前更好数值精确度,当然我们也可以不用。。这个参数定义_ _FAST_MATH_ _这个宏,相当于后面要说的6个浮点相关运算参数的并集,which对我来说长得相当古怪!)-ffinite-math-onlyDisregard infinities and NaN ("not a number") values.浮点相关运算参数。我没看懂“Disregard”到底是指丢弃,还是说不检查就接收。。-ffreestandingCompile 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-functionsEnable/disable inline functions.允许/不允许内联函数-fno-math-errnoDisable the errno variable for simple math functions.浮点相关运算参数。浮点数学函数中出错了不使用errno这个全局变量?-fno-trapping-mathGenerate "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-mathDon't disregard the rounding-mode features of the floating-point environment (experimental).浮点相关运算参数-fno-rounding-math的opposite。使用一些规则来舍入?-fsignaling-nansAllow all exceptions raised by signaling NaNs (experimental).浮点相关运算参数-fno-signaling-nans的opposite。这个singal又拿不准了。。数学参数我放弃了。。-fsyntax-onlyDon't compile or link; just test input for syntax.只测试输入语法有效性(比如先找点Warning之类的,不用花时间编译)-funroll-loops, -fno-unroll-loopsEnable/disable loop optimization.对循环做优化(比如把一些小循环的跳转改成线性的代码,貌似会使文件增大?)-funsafe-math-optimizationsPermit optimizations that don't conform to standards and/or don't verify values.浮点相关运算参数。看名字吧。。。-fverbose-asmInclude 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 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 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.”-lbasenameLink 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= cpuIntel x86: Generate model-specific code.为某个平台优化,第一个m意思是machine或者model。对于x86体系来说,-mcpu和-mtune是一样,-march可以为不同cpu产生优化的代码,比如-march=athlon-4(具体的cpu abbr.看gcc manual)-mcpu= cpuSparc, ARM, and RS/6000-PowerPC: Generate model-specific code.Intel x86: Optimize scheduling for the specified CPU model.为某个平台优化,对于x86和非x86体系来说,-m系列参数意义有点不一样,见前面-marchQuote:“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= cpuOptimize 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.”-nostartfilesDon'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.”-nostdlibDon't link with the standard library.不连接C Stanndard Library-o fileDirect output to the specified file.指定输出文件名。-O0Turn off all optimization options.不优化。-O, -O1Perform some optimization without taking much time.优化-O2Perform more optimization, including data flow analysis.再优化-O3
Perform still more optimization, including inline function compilation.优化到底-OsOptimize for size.只在文件大小方面做优化-pLink 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.”-pedanticOutput warnings on nonstandard usage.为非标准用法产生Warning(比如ANSI C不包括但是GUN C扩展的地方,见-std)-pedantic-errorsFail on nonstandard usage.这个比较狠,编写portable代码应该用上-pgLink in code to output profiling information for gprof.为GUN Profiler,gprof输出profiling information,这次输出文件叫gmon.out-sStrip symbol tables from executable file.优化参数。在执行文件中去除符号表(执行文件里面有符号表的话有什么好处呢?回去复习编译吧。。-_-)Quote:“This makes the finished program file significantly smaller, and is often used in building a production version.”-SPreprocess and translate into assembly language only.预处理,编译,到生成*.s为止,不汇编。-save-tempsSave intermediate output files.留下所有编译过程中产生的文件:.i、.s、.o-sharedCreate a shared object file for dynamic linking.生成.so文件,类似dll-staticDon't link to shared object files.只静态连接,就是说生成的文件不会去连接.so文件-std=iso9899:1990-std=c89-ansiSupport ISO/IEC 9899:1990.都是一样的。支持ANSI C标准,与标准冲突的扩展被disable(比如GUN的tyepeof操作符,好东西啊。。)-std=iso9899:199409Support ISO/IEC 9899:1989 and AMD1.另一个标准-std=c99Support ISO/IEC 9899:1999.不知道现在对C99的支持做完了没?-std=gnu89Like -ansi, plus GNU extensions (default).默认-std选项,看名字-std=gnu99Like -std=c99, plus GNU extensions.估计是现在的默认了-traditionalSupport old-style C. Deprecated; supported only with -E.注意:“supported only with –E”,只在预处理的时候有用-trigraphsSupport ISO C trigraphs.三连符?用来表示那些键盘上没有的字符(可能是遗留问题?)
Trigraph
Equivalent
??(
[
??)
]
??
{
??>
}
??=
#
??/
\
??!
|
??'
^
??-
~
-U name"Undefine" the symbol name.和-D对应的-vBe verbose: print the options applied at each step of compiling.Java也有个-verbose,Hoho--versionOutput GCC version and license information.查看版本和许可信息-w
Disable all warnings.不产生任何Warning-Wa, option[, option[...]]Pass options to assembler command line.给汇编器as传命令行参数,估计我很难用到-WallOutput warnings about a broad range of problems in source code.第一个大写W是warning的意思。但是-Wall不是产生所有种类的warning,还是有些要显示指明(比如-Wshadow)-Wl, option[, option[...]]Pass options to linker command line.给连接器ld传命令行参数-WerrorFail on all warnings.这个比-pedantic-errors更狠-WextraOutput warnings about legal but questionable usage.这个貌似是最verbose的warning了-WtraditionalWarn about differences to old-style C.看名字-fmerge-constantsPut identical constants in a single location.优化参数,再补一句:“even across different source files”-x filetypeTreat subsequent files as being of the specified type.这里filetype的选项有“c, c-header, cpp-output, assembler (meaning that the file contains assembly language), assembler-with-cpp, or none.”所有出现在-x之前的文件被当作-x指定的filetype,常用在没用标准扩展名的时候
Environment Variables环境变量
CPATH, C_INCLUDE_PATHColon-separated list of directories to search for header files, after those indicated by -Idirectory on the command line.和-I一起,#include的时候用,冒号分隔COMPILER_PATHColon-separated list of directories to search for GCC's own subprogram files.GCC_EXEC_PREFIXA prefix for GCC to add to the names of its subprograms when invoking them. May end with a slash.LIBRARY_PATHColon-separated list of directories to search for linker and library files, after directories specified by -Ldirectory on the command line.和-L一起,连接library的时候用LD_LIBRARY_PATHColon-separated list of directories to search for shared library files. Read not by GCC, but by executables dynamically linked against shared libraries.找.so的路径,比如/usr/lib/、%SystemRoot%\system32\之类的TMPDIRDirectory to use for temporary files.临时文件路径,比如/tmp
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/20619/showart_1108608.html |
|