zoukankan      html  css  js  c++  java
  • gcc常用参数和环境变量小结

    (in alphabet,整理自《C In A Nutshell》1e,Section18.9,加点自己的理解)

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

    -trigraphs
    Support ISO C trigraphs.
    三连符?用来表示那些键盘上没有的字符(可能是遗留问题?)

    Trigraph

    Equivalent

    ??(

    [

    ??)

    ]

    ??<

    {

    ??>

    }

    ??=

    #

    ??/

    \

    ??!

    |

    ??'

    ^

    ??-

    ~


    -U name
    "Undefine" the symbol name.
    和-D对应的

    -v
    Be verbose: print the options applied at each step of compiling.
    Java也有个-verbose,Hoho

    --version
    Output GCC version and license information.
    查看版本和许可信息

    -w
    Disable all warnings.
    不产生任何Warning

    -Wa, option[, option[...]]
    Pass options to assembler command line.
    给汇编器as传命令行参数,估计我很难用到

    -Wall
    Output 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传命令行参数

    -Werror
    Fail on all warnings.
    这个比-pedantic-errors更狠

    -Wextra
    Output warnings about legal but questionable usage.
    这个貌似是最verbose的warning了

    -Wtraditional
    Warn about differences to old-style C.
    看名字

    -fmerge-constants
    Put identical constants in a single location.
    优化参数,再补一句:“even across different source files”

    -x filetype
    Treat 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_PATH
    Colon-separated list of directories to search for header files, after those indicated by -Idirectory on the command line.
    和-I一起,#include的时候用,冒号分隔

    COMPILER_PATH
    Colon-separated list of directories to search for GCC's own subprogram files.

    GCC_EXEC_PREFIX
    A prefix for GCC to add to the names of its subprograms when invoking them. May end with a slash.

    LIBRARY_PATH
    Colon-separated list of directories to search for linker and library files, after directories specified by -Ldirectory on the command line.
    和-L一起,连接library的时候用

    LD_LIBRARY_PATH
    Colon-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\之类的

    TMPDIR
    Directory to use for temporary files.
    临时文件路径,比如/tmp


    Last but not least:Resources We Can Use

    利用gcc生成静态库和动态库
    学习GCC Complete Reference总结
    《GCC:the Complete Reference》

  • 相关阅读:
    前端开发:如何正确地跨端?
    开源微服务运行时 Dapr 发布 1.0 版本
    Flink 如何实时分析 Iceberg 数据湖的 CDC 数据
    为了让你在“口袋奇兵”聊遍全球,Serverless 做了什么?
    Serverless 如何在阿里巴巴实现规模化落地?
    altas(ajax)控件(十三):悬浮菜单HoverMenu
    MasterPage嵌套及MasterPage中的控件和变量的访问
    Linux下将CD音乐提取为mp3的方法和中文乱码问题的解决
    altas(ajax)控件(十四):为下拉控件添加快捷键查找功能的ListSearchExtender
    在atlas(ajax)中请不要使用Response.Write,请使用ClientScript.RegisterClientScriptBlock替换
  • 原文地址:https://www.cnblogs.com/dxz/p/gcc_option_and_env_var.html
Copyright © 2011-2022 走看看