man_gcc部分

13 篇文章 0 订阅
3 篇文章 0 订阅

loading

名词解释
       C/C++程序编译器
简单语法
	gcc [-c│-S│-E] [-std=standard]
           [-g] [-pg] [-Olevel]
           [-Wwarn...] [-pedantic]
           [-Idir...] [-Ldir...]
           [-Dmacro[=defn]...] [-Umacro]
           [-foption...] [-mmachine-option...]
           [-o outfile] infile...
	   仅列出常用的选项。更多详情看下面。g++继承gcc大部分选项\
描述 
	当你使用gcc时,一般会预处理,编译,汇编,连接。其他选项允许过程在某一阶段中断。
	例如 -c选项不会进行连接,输出的是汇编器执行以后的文件
	(二进制文件可以通过命令查看:  od  -tx1 -Ax filename.o)。
         
	还有一些其他的过程选项。由于使用得少,大部分没有记录在这里
         
	 gcc用来编译C程序

	 gcc可以接受文件名作为操作数,许多选项名字有大量字母,因此可能会有些单选项
         不能被组合比如-dr 和-d  -r不一样

         大部分参数可以无序使用。参数多次使用也没问题。如果使用 -L多次,那么将会按照
	 顺序查询相应的目录

         许多名字很长的选项会使用第一个字幕,例如 -fstrength-reduce  同-f;
	 -Wformat 同-W,这类的有取反的 -ffoo  反 -fno-foo

选项
	选项摘要
	下面将根据类型分组解释对应的参数

	通用选项参数
	-c  -S  -E  -o file  -combine -pipe  -pass-exit-codes -x language
        -v  -###  --help  --target-help  --version

        
	C语言专用选项参数
         -ansi  -std=standard  -fgnu89-inline -aux-info filename -fno-asm
           -fno-builtin  -fno-builtin-function -fhosted  -ffreestanding
           -fms-extensions -trigraphs  -no-integrated-cpp  -traditional
           -traditional-cpp -fallow-single-precision  -fcond-mismatch
           -fsigned-bitfields  -fsigned-char -funsigned-bitfields  -fun-
           signed-char

        
	C++专用选项参数
         -fabi-version=n  -fno-access-control  -fcheck-new -fconserve-space
           -ffriend-injection  -fno-const-strings -fno-elide-constructors
           -fno-enforce-eh-specs -ffor-scope  -fno-for-scope  -fno-gnu-key-
           words -fno-implicit-templates -fno-implicit-inline-templates
           -fno-implement-inlines  -fms-extensions -fno-nonansi-builtins
           -fno-operator-names -fno-optional-diags  -fpermissive -frepo
           -fno-rtti  -fstats  -ftemplate-depth-n -fno-threadsafe-statics
           -fuse-cxa-atexit  -fno-weak  -nostdinc++ -fno-default-inline
           -fvisibility-inlines-hidden -Wabi  -Wctor-dtor-privacy -Wnon-vir-
           tual-dtor  -Wreorder -Weffc++  -Wno-deprecated  -Wstrict-null-sen-
           tinel -Wno-non-template-friend  -Wold-style-cast -Woverloaded-vir-
           tual  -Wno-pmf-conversions -Wsign-promo

         Objective-C and Objective-C++ 专用选项参数
	 -fconstant-string-class=class-name -fgnu-runtime  -fnext-runtime
           -fno-nil-receivers -fobjc-call-cxx-cdtors -fobjc-direct-dispatch
           -fobjc-exceptions -fobjc-gc -freplace-objc-classes -fzero-link
           -gen-decls -Wassign-intercept -Wno-protocol  -Wselector
           -Wstrict-selector-match -Wundeclared-selector

	 输出信息设置选项参数
           -fmessage-length=n -fdiagnostics-show-location=[once│every-line]
           -fdiagnostics-show-options
	 
	警告通用选项参数Warning Options
           -fsyntax-only  -pedantic  -pedantic-errors -w  -Wextra  -Wall
           -Waggregate-return -Wno-attributes -Wc++-compat -Wcast-align
           -Wcast-qual  -Wchar-subscripts  -Wcomment -Wconversion  -Wno-depre-
           cated-declarations -Wdisabled-optimization  -Wno-div-by-zero
           -Wno-endif-labels -Werror  -Werror-implicit-function-declaration
           -Wfatal-errors  -Wfloat-equal  -Wformat  -Wformat=2 -Wno-for-
           mat-extra-args -Wformat-nonliteral -Wformat-security  -Wformat-y2k
           -Wimplicit  -Wimplicit-function-declaration  -Wimplicit-int -Wim-
           port  -Wno-import  -Winit-self  -Winline -Wno-int-to-pointer-cast
           -Wno-invalid-offsetof  -Winvalid-pch -Wlarger-than-len  -Wun-
           safe-loop-optimizations  -Wlong-long -Wmain  -Wmissing-braces
           -Wmissing-field-initializers -Wmissing-format-attribute  -Wmiss-
           ing-include-dirs -Wmissing-noreturn -Wno-multichar  -Wnonnull
           -Wpacked  -Wpadded -Wparentheses  -Wpointer-arith
           -Wno-pointer-to-int-cast -Wredundant-decls -Wreturn-type  -Wse-
           quence-point  -Wshadow -Wsign-compare  -Wstack-protector
           -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch  -Wswitch-default
           -Wswitch-enum -Wsystem-headers  -Wtrigraphs  -Wundef  -Wuninitial-
           ized -Wunknown-pragmas  -Wno-pragmas -Wunreachable-code -Wunused
           -Wunused-function  -Wunused-label  -Wunused-parameter
           -Wunused-value  -Wunused-variable  -Wvariadic-macros
           -Wvolatile-register-var  -Wwrite-strings

       C语言专用警告选项参数C-only Warning Options
           -Wbad-function-cast  -Wmissing-declarations -Wmissing-prototypes
           -Wnested-externs  -Wold-style-definition -Wstrict-prototypes
           -Wtraditional -Wdeclaration-after-statement -Wpointer-sign

       调试选项参数Debugging Options
           -dletters  -dumpspecs  -dumpmachine  -dumpversion -fdump-unnumbered
           -fdump-translation-unit[-n] -fdump-class-hierarchy[-n]
         -----------省略-------------

       最优化选项参数Optimization Options
           -falign-functions[=n]  -falign-jumps[=n] -falign-labels[=n]
           -falign-loops[=n] -fmudflap -fmudflapth -fmudflapir -fbranch-proba-
         -----------省略-------------

       预处理器选项参数 Preprocessor Options
           -Aquestion=answer -A-question[=answer] -C  -dD  -dI  -dM  -dN
           -Dmacro[=defn]  -E  -H -idirafter dir -include file  -imacros file
           -iprefix file  -iwithprefix dir -iwithprefixbefore dir  -isystem
           dir -isysroot dir -M  -MM  -MF  -MG  -MP  -MQ  -MT  -nostdinc -P
           -fworking-directory  -remap -trigraphs  -undef  -Umacro  -Wp,option
           -Xpreprocessor option

       汇编器选项参数Assembler Option
           -Wa,option  -Xassembler option

       连接器选项参数Linker Options
           object-file-name  -llibrary -nostartfiles  -nodefaultlibs  -nost-
           dlib -pie -rdynamic -s  -static  -static-libgcc  -shared
           -shared-libgcc  -symbolic -Wl,option  -Xlinker option -u symbol

       目录选项参数Directory Options
           -Bprefix  -Idir  -iquotedir  -Ldir -specs=file  -I- --sysroot=dir

       目标选项参数Target Options
           -V version  -b machine

       与机器相关选项参数Machine Dependent Options
           
	----------------------省略---------------------

       代码生成选项参数Code Generation Options
           -fcall-saved-reg  -fcall-used-reg -ffixed-reg  -fexceptions
           -fnon-call-exceptions  -funwind-tables -fasynchronous-unwind-tables
           -finhibit-size-directive  -finstrument-functions -fno-common
           -----------省略-------------


       控制输出类型参数Options Controlling the Kind of Output

       编译涉及到有序的四个步骤:预处理,编译,汇编,链接;
       gcc可以预处理和编译许多文件作为一个或多个汇编器的输入文件;
       汇编器可以把许多程序文件生成对象文件(中间文件);
       连接器可以把所有对象文件连接成一个可执行文件;

       对于任意的输入问价,文件后缀决定了它的编译动作 
       

       file.c  C语言源文件 预处理-编译-汇编-链接
           C source code which must be preprocessed.

       file.i  C语言源文件 编译-汇编-链接
           C source code which should not be preprocessed.

       file.ii C++语言源文件 编译-汇编-链接
           C++ source code which should not be preprocessed.

       file.m Objective-C语言源文件 预处理-编译-汇编-链接
           Objective-C source code.  Note that you must link with the libobjc
           library to make an Objective-C program work.

       file.mi Objective-C语言源文件 编译-汇编-链接
           Objective-C source code which should not be preprocessed.

       file.mm Objective-C++语言源文件 预处理-编译-汇编-链接.
       file.M   Objective-C++语言源文件 预处理-编译-汇编-链接
           Objective-C++ source code.  Note that you must link with the
           libobjc library to make an Objective-C++ program work.  Note that
           .M refers to a literal capital M.

       file.mii Objective-C++语言源文件 编译-汇编-链接
           Objective-C++ source code which should not be preprocessed.

       file.h  头文件C, C++, Objective-C or Objective-C++ ,作为预编译头
           C, C++, Objective-C or Objective-C++ header file to be turned into
           a precompiled header.

       file.cc
       file.cp
       file.cxx
       file.cpp
       file.CPP
       file.c++
       file.C    C++语言源文件 预处理-编译-汇编-链接
           C++ source code which must be preprocessed.  Note that in .cxx, the
           last two letters must both be literally x.  Likewise, .C refers to
           a literal capital C.

       file.mm
       file.M   Objective-C++语言源文件 预处理-编译-汇编-链接
           Objective-C++ source code which must be preprocessed.

       file.mii   Objective-C++语言源文件 编译-汇编-链接
           Objective-C++ source code which should not be preprocessed.

       file.hh
       file.H    头文件 C++,作为预编译头 
           C++ header file to be turned into a precompiled header.

       file.f
       file.for
       file.FOR  编译-汇编-链接
           Fixed form Fortran source code which should not be preprocessed.

       file.F
       file.fpp
       file.FPP  预处理-编译-汇编-链接
           Fixed form Fortran source code which must be preprocessed (with the
           traditional preprocessor).

       file.f90
       file.f95 编译-汇编-链接
           Free form Fortran source code which should not be preprocessed.

       file.F90
       file.F95  预处理
           Free form Fortran source code which must be preprocessed (with the
           traditional preprocessor).

       file.ads 声明a library unit 
           Ada source code file which contains a library unit declaration (a
           declaration of a package, subprogram, or generic, or a generic
           instantiation), or a library unit renaming declaration (a package,
           generic, or subprogram renaming declaration).  Such files are also
           called specs.

       file.adb 主体部分
           Ada source code file containing a library unit body (a subprogram
           or package body).  Such files are also called bodies.

       file.s   汇编代码
           Assembler code.

       file.S   汇编代码需要 预处理-编译-汇编-链接
           Assembler code which must be preprocessed.

        其他直接被连接的文件、无法识别的文件将采用一下方法
           你可以明确指定输入文件语言通过选项参数 -x

       -x language
           明确指定接下来的文件使用的语言
           language的取值如下
                   c  c-header  c-cpp-output
                   c++  c++-header  c++-cpp-output
                   objective-c  objective-c-header  objective-c-cpp-output
                   objective-c++ objective-c++-header objective-c++-cpp-output
                   assembler  assembler-with-cpp
                   ada
                   f95  f95-cpp-input
                   java
                   treelang

       -x none 关闭指定接下来文件使用语言,采用默认方式 

       -pass-exit-codes
             正常程序遇到一个编译错误就会退出,并返回不成功错误代码,
	     如果使用 -pass-exit-codes这个选项参数gcc将会返回每个阶段
	     产生的数值上最大的错误,并返回错误指示
************************************************************    
      没有参数选项 -E -c -S  将链接(预处理-编译-汇编-链接)
      [工程内调用extern 函数/全局变量 等处理(无函数定义等会报错)(全局变量不同源文件重复定义报错)]
       如果只需要某些编译阶段,可以使用选项参数-x 或者采用对应的文件后缀
       使得gcc知道开始位置。而选项参数 -c, -S, or -E设置编译停止位置。
       (for example, -x cpp-output -E) instruct gcc to do nothing at all.
      gcc main.c print.c  -I./inc  #可执行文件 a.out (预处理-编译-汇编-链接)
      gcc  main.c print.o -I./inc  #可执行文件 a.out (main.c预处理-编译-汇编-链接/ print.o链接)
      gcc main.o print.o -o EXea   #可执行文件 EXea (链接)
      gcc main.o print.s           #可执行文件 a.out (main.c链接/ print.s汇编-链接)
      ************************************** 
       -c  汇编(预处理-编译-汇编),不链接

           默认 输入文件后缀 .c, .i, .s, etc.,  输出文件后缀 .o
           gcc -c print.c -I./inc #生成 print.o(预处理-编译-汇编)
           gcc -c file.i	  #生成 file.o(编译-汇编)
	   gcc -c print.s -o my.o #生成 my.o(汇编)
           无法识别的文件后缀将被忽略,不编译也不汇编
      **************************************
       -S  编译(预处理-编译),不汇编  The
           output is in the form of an assembler code file for each non-assem-
           bler input file specified.

           默认 输入文件后缀.c, .i, etc.,  输出文件后缀 .s(汇编代码)
           gcc -S print.c -I./inc   #生成 print.s (预处理-编译)
           gcc -S file.i            #生成 file.s  (编译)
	   gcc -S main.c            #main.s (编译(这里需要main.c中没有#include"filename"且代码中类型在main.c中) 
           输入文件不许需要预编译的将被忽略
      **************************************
       -E  预处理,不需要编译(把每个原文件的文件头载入)
           根据格式输入    标准输出 可以用 > filename 重定向到只定文件 或者-o filename
           gcc -E print.c -I./inc      #直接屏幕打印出来  预处理 当前位置的inc 目录中放print.c有的头文件
           gcc -E print.c -I./inc > file.i#重定向到 file.i文件 预处理 当前位置的inc 目录中放print.c有的头文件
	   gcc -E main.c  -o main.i      #main.i文件 预处理(这里需要main.c中没有#include"filename")     
           输入文件不需要预处理的将被忽略
      **************************************
       -o filename
           指定输出文件(预处理输出文件 ,汇编输出文件 ,预编译输出对象文件(中间文件),链接输出可执行文件)
      **************************************    
	   如果没有指定-o filename这个选项参数 ,
	   预处理   文件默认 标准输出文件
	   预处理   预编译头文件默认			source.suffix.gch
	   编译   文件默认 标准输出文件			source.s
	   汇编输出 文件默认 对象文件(中间文件)默认	source.o
	   链接输出 可执行文件默认			a.out
      

       -v  打印(标准出错输出)编译阶段命令,编译器驱动、预处理器、预编译器版本

       -###
           Like -v except the commands are not executed and all command argu-
           ments are quoted.  This is useful for shell scripts to capture the
           driver-generated command lines.

       -pipe
           Use pipes rather than temporary files for communication between the
           various stages of compilation.  This fails to work on some systems
           where the assembler is unable to read from a pipe; but the GNU
           assembler has no trouble.

       -combine
          如果正在编译多个源文件,则该选项告诉
	驱动程序立即将所有源文件传递给编译器(用于
	编译器可以处理的这些语言)。这将
	允许模块间分析(IMA)是由编译器执行。
	目前只有C语言支持。如果传递源文件给多种语言的驱动程序,使用
	此选项中,驱动程序将调用编译器(s)的支持
	每一个IMA,把文件传给对应的编译器。对于那些语言不支持IMA这
	选项将被忽略。有一个语言的源文件编译器就会被调用一次。
	如果-combine和选项参数  -save-temps一起使用,
	编译器会生成多个预处理文件(一个源文件的一个),
	但只有一个(组合).o or .s 文件.

       --help
           Print (on the standard output) a description of the command line
           options understood by gcc.  If the -v option is also specified then
           --help will also be passed on to the various processes invoked by
           gcc, so that they can display the command line options they accept.
           If the -Wextra option is also specified then command line options
           which have no documentation associated with them will also be dis-
           played.

       --target-help
           Print (on the standard output) a description of target specific
           command line options for each tool.

       --version
           Display the version number and copyrights of the invoked GCC.

  ---------------省略-----------------
预处理器选项参数 Preprocessor Options
	   -Aquestion=answer -A-question[=answer] -C  -dD  -dI  -dM  -dN
           -Dmacro[=defn]  -E  -H -idirafter dir -include file  -imacros file
           -iprefix file  -iwithprefix dir -iwithprefixbefore dir  -isystem
           dir -isysroot dir -M  -MM  -MF  -MG  -MP  -MQ  -MT  -nostdinc -P
           -fworking-directory  -remap -trigraphs  -undef  -Umacro  -Wp,option
           -Xpreprocessor option
--------------------------------------
           -D name
	   在命令行增宏名,#define name 定义为空

	   -D name=define
           命令行加定义,不为空,#define  name(args,...)  defination
              -D' name(args,...)=defination'

	   -U name
	   取消先前宏定义name

	   -undef
	   不预定义系统或gcc指定的宏,标准预定义保留

	   -I dirpath
	   增加头文件(header)库头目录到目录搜索链中
	   先在-I dirpaht中搜索
	   再搜索系统库目录集合path,如果目录在系统库目录集合path中,
	   那么选项参数忽略。这样可以确保系统目录的默认搜索顺序和系统标头的特殊处理不会失败
	  
	   -I-
	   在-I-选项参数之前的-I搜索#include "file"不搜索#include <file>
	   在-I-选项参数之后的-I全部搜索
	   
           -nostdinc
	   不搜索系统库头目录里的文件,
	   搜索指定-I dirpath 指定库头目录里面的文件

           -nostdinc++
	   不搜索C++标准库,搜索其他的标准库

           -include file
	   相当于原文件第一行有#include "file"

	   -imacros file
	   宏文件,里面没有声明

	   -idirafter dirpath
	   在搜索dir在系统库头目录和和-I dirpth指定目录之后才
	   搜索 dirpath,当作系统=库头目录使用 #include<filename>

           -iprefix prefix
	   指定前缀prefix加到-iwithprefix option选项参数的option之前,
	   如果prefix是个目录,那么目录需要用反斜杠/结尾

           -iwithprefix dir
           -iwithprefixbefore dir
	   给dir增加前缀,并加入库头目录搜索路径中,其中
           -iwithprefixbefore dir加到 -I dirpth中
           -iwithprefix dir加到-idirafter dirpth中

	   -isysroot dir
           同--sysroot optio

	   -isystem dir
           搜索顺序-I dirpath  ->  -isystem dir  ->  $PATH

	   -iquote dir
	   搜索按-iquote dir  -> -I dirpath ->$PATH 搜索#include "file"
	   不搜索#include <file>"
           
	   ---------------省略-----------------

           -fexec-charset=charsetChoise
	   设置执行编码,默认UTF-8;charsetChoise可以选择系统内的所有编码类型
	   Linux查看命令 iconv -l

	   -fwide-exec-charset=charset
	   设置宽执行字符。默认的UTF-32或者UTF-16的,宽度为wchar_t的宽度

           -fworking-directory
	   使预处理知道当前编译器的工作目录,反-fno-working-directory

           -fno-show-column
	   不打印诊断行数

           -A predicate=answer
	   增加断言

	   -A -predicate=answer
	   取消断言

           -dCHARS
	   -dM  在预处理中形成所有宏定义序列
	   -dD  和-dM差别,这个不包括预处理宏,包括定义宏和预处理结果(宏扩展),输出到标准输出文件
	   -dN  和dD类似,但只有宏名没有宏扩展
	   -dI  输出#include directives 到预处理结果
--------------------------省略-----------------
汇编器选项参数Assembler Option
           -Wa,option  -Xassembler option
-----------------------------------------
           -Wa,option
           传递option作为汇编选项,如果option包含逗号,将被根据逗号分成多个options

	   -Xassembler option
           传递option作为汇编选项,可以使用gcc无法识别的系统指定的汇编选项
	   如果需要传递option作为参数,需要使用-Xassembler twice两次,
	   一次选项,一次参数
------------------------------------   
       连接器选项参数Linker Options
           object-file-name  -llibrary -nostartfiles  -nodefaultlibs  -nost-
           dlib -pie -rdynamic -s  -static  -static-libgcc  -shared
           -shared-libgcc  -symbolic -Wl,option  -Xlinker option -u symbol
-------------------------------------
       object-file-name
       如果链接成功,这些将作为连接器的输入
        有选项参数-c -S -E的命令没有链接

        -llibrary
       -l library
        需要链接的library(两个一样,第二个仅适用POSIX,不推荐用第二个)
	文件名libmy.a  使用-lmy
        有序加载 foo.o -llibmy bar.o  foo.o能加载my中的,bar.o不行
        链接器搜索library库文件标准清单,实际文件名为liblibrary.a;连接器使用
	这个作为他的精确指定名
	增加的搜索标准系统目录使用选项参数-Ldirpath

	----------省略-----
	-rdynamic
	   Pass the flag -export-dynamic to the ELF linker, on targets that
           support it. This instructs the linker to add all symbols, not only
           used ones, to the dynamic symbol table. This option is needed for
           some uses of "dlopen" or to allow obtaining backtraces from within
           a program.

       -s  Remove all symbol table and relocation information from the exe-
           cutable.

       -static
           On systems that support dynamic linking, this prevents linking with
           the shared libraries.  On other systems, this option has no effect.

       -shared
           产生可以被其他对象共享链接的对象,不是所有的系统都支持这个选项
	   必须指定选项参数去生成代码(-fpic, -fPIC, or model suboptions)


-----------------------------------------------

       目录选项参数Directory Options
           -Bprefix  -Idir  -iquotedir  -Ldir -specs=file  -I- --sysroot=dir

       目标选项参数Target Options
           -V version  -b machine

       与机器相关选项参数Machine Dependent Options


 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值