Gcc User Manual (1)

Source: Internet
Author: User
Tags builtin
Gcc User Manual (1)-Linux general technology-Linux programming and kernel information. For details, see the following. NAME

Gcc, g ++-GNU Project C and C ++ Compiler (egcs-1.1.2)

Overview (SYNOPSIS)

Gcc [option | filename]...

G ++ [option | filename]...

WARNING)

The content on this manual page is taken from the complete documentation of the gnu c compiler and is limited to explaining the meaning of the options.

Unless manually maintained, the manual page will not be updated. If any conflict is found between the manual page and the software, please
Check the Info file. The Info file is an authoritative document.

If we find that the contents of this album are out of date and cause obvious confusion and complaints, we will stop publishing.
It. It is impossible to have other options, such as updating the Info file and updating the man manual at the same time, because other workers who maintain GNU CC
There is no time for us to do this. The GNU Project thinks that man's manual is an outdated product and should use time in other ways.
Location.

If you need complete and up-to-date documentation, see the Info file 'gcc 'or Using and Porting gnu cc (
For version 2.0) (Use and port gnu cc 2.0) manual. Both are from the original Texinfo file gcc
Texinfo.

DEscriptION)

C and C ++ compilers are integrated. They must process one or more input files in four steps: preprocessing
(Preprocessing), compilation, assembly, and linking. After the source file
The language of the source file identified by the suffix name, but for the compiler, the suffix name controls the default settings:

Gcc

The pre-processed file (. I) is considered as a C file, and the C-form connection is set.

G ++

The pre-processed file (. I) is considered as a C ++ file, and a connection in the C ++ format is set.

The source file suffix indicates the language type and subsequent operations:

C-C source program; preprocessing, compilation, assembly

C ++ source program; preprocessing, compilation, and compilation

Cc C ++ source program; preprocessing, compilation, and compilation

Cxx C ++ source program; preprocessing, compilation, and compilation

M Objective-C source program; preprocessing, compilation, assembly

I. pre-processed C files; compilation and compilation

Ii. pre-processed C ++ files; compilation and compilation

S assembly language source program; Assembly

S assembly language source program; preprocessing, assembly

H pre-processor file; usually not displayed on the command line

Other suffixed files are passed to the connector (linker). These files generally include:

O target file)

A Archive file)

Unless the-c,-S, or-E option is used (or the compilation error stops the complete process), the connection is always final.
In the connection phase, all. o files corresponding to the source program,-l library files, unrecognizable file names (
Including the specified. o target file and. a library file) are passed to the connector in the order in the command line.

OPTIONS)

The option must be given separately: '-write' is totally different from'-d-R '.

Most '-F' and'-W' options have two opposite formats:-fname and-fno-name (or-Wname and-Wno
-Name). Only formats that are not the default options are listed here.

The following is a summary of all options, which are grouped by type and explained in later chapters.

Overall Option)

-C-S-E-o file-pipe-v-x language

Language Option)

-Ansi-fall-virtual-fcond-mismatch-fdollars-in-identifiers-fenum-int-
Equiv-fexternal-templates-fno-asm-fno-builtin-fhosted-fno-hosted-f
Freestanding-fno-strict-prototype-fsigned-bitfields
-Fsigned-char-fthis-is-variable-funsigned-bitfields-funsigned-char-f
Writable-strings-traditional-cpp-trigraphs

Warning Option)

-Fsyntax-only-pedantic-errors-w-W-Wall-Waggregate-return
-Wcast-align-Wcast-qual-Wchar-subscript-Wcomment-Wconversion-Wenum-
Clash-Werror-Wformat-Wid-clash-len-Wimplicit-int-Wimplic
It-function-declaration-Winline-Wlong-long-Wmain-Wmissing-prototypes
-Wmissing-declarations-Wnested-externs-Wno-import-Wparentheses-Wpoi
Nter-arith-Wredundant-decls-Wreturn-type-Wshadow-Wstrict-prototypes
-Wswitch-Wtemplate-debugging-Wtraditional-Wtrigraphs-Wuninitialized
-Wunused-Wwrite-strings

Debugging Option)

-A-dletters-fpretend-float-g-glevel-gcoff-gxcoff +-gdwarf
-Gdwarf +-gstabs +-ggdb-p-pg-save-temps-print-file-name = libr
Ary-print-libgcc-file-name-print-prog-name = program

Optimization Option)

-Fcaller-saves-fcse-follow-jumps-fcse-skip-blocks-fdelayed-branch-fe
Lide-constructors-fexpensive-optimizations-ffast-math-ffloat-store-f
Force-addr-fforce-mem-finline-functions-fkeep-inline-functions-fmemo
Ize-lookups-fno-default-inline-fno-defer-pop-fno-function-cse-fno-in
Line-fno-peephole-fomit-frame-pointer-frerun-cse-after-loop-fschedul
E-insns-fschedule-insns2-fstrength-reduce-fthread-jumps-funroll-all-
Loops-funroll-loops-O-O2-O3

Preprocessor Option)

-Aassertion-C-dD-dM-dN-Dmacro [= defn]-E-H-idirafter dir-include
File-imacros file-iprefix file-iwithprefix dir-M-MD-MM-MMD-nostd
Inc-P-Umacro-undef

Assembler Option)

-Wa, option

Linker Option)

-Llibrary-nostartfiles-nostdlib-static-shared-symbolic-Xlinker opt
Ion-Wl, option-u symbol

Directory Option)

-Bprefix-Idir-I-Ldir

Target Option)

-B machine-V version

Configuration Dependent Option)

M680x0 Option

-M68000-m68020-m68020-40-m68030-m68040-m68881-mbitfield-mc68000-
Mc68020-mfpa-mnobitfield-mrtd-mshort-msoft-float

VAX Option

-Mg-mgnu-munix

Type

-Mepilogue-mfpu-mhard-float-mno-fpu-mno-epilogue-msoft-float-mspar
Clite-mv8-msupernames-mcypress

Convex options

-Margcount-mc1-mc2-mnoargcount

AMD29K Option

-M29000-m29050-mbw-mdw-mkernel-registers-mlarge-mnbw-mnodw-msmal
L-mstack-check-muser-registers

M88K Option

-M88000-m88100-m88110-mbig-pic-mcheck-zero-division-mhandle-large-s
Hift-midentify-revision-mno-check-zero-division-mno-ocs-debug-info-m
No-ocs-frame-position-mno-optimize-arg-area-mno-serialize-volatile-mn
O-underscores-mocs-debug-info-mocs-frame-position-moptimize-arg-area
-Mserialize-volatile-mshort-data-num-msvr3-msvr4-mtrap-large-shift-
Muse-div-instruction-mversion-03.00-mwarn-passed-structs

RS6000 options

-Mfp-in-toc-mno-fop-in-toc

RT Option

-Mcall-lib-mul-mfp-arg-in-fpregs-mfp-arg-in-gregs-mfull-fp-blocks-mh
C-struct-return-min-line-mul-mminimum-fp-blocks-mnohc-struct-return

MIPS options

-Mcpu = cpu type-mips2-mips3-mint64-mlong64-mmips-as-mgas-mrnames-
Mno-rnames-mgpopt-mno-gpopt-mstats-mno-stats-mmemcpy-mno-memcpy-m
No-mips-tfile-mmips-tfile-msoft-float-mhard-float-mabicils-mno-abi
CILS-mhalf-pic-mno-half-pic-G num-nocpp

I386 Option

-Mbench-mno-486-msoft-float-mno-fp-ret-in-387

HPPA options

-Mpa-risc-1-0-mpa-risc-1-1-mkernel-mshared-libs-mno-shared-libs-mlo
Ng-CILS-mdisable-fpregs-mdisable-indexing-mtrailing-colon

I960 Option

-Mcpu-type-mnumerics-msoft-float-mleaf-procedures-mno-leaf-procedure
S-mtail-call-mno-tail-call-mcomplex-addr-mno-complex-addr-mcode-ali
Gn-mno-code-align-mic-compat-mic2.0-compat-mic3.0-compat-masm-compa
T-mintel-asm-mstrict-align-mno-strict-align-mold-align-mno-old-alig
N

DEC Alpha Option

-Mfp-regs-mno-fp-regs-mno-soft-float-msoft-float

System V Option

-G-Qy-Qn-YP, paths-Ym, dir

Code Generation Option)

-Fcall-saved-reg-fcall-used-reg-ffixed-reg-finhibit-size-directive-f
Nonnull-objects-fno-common-fno-ident-fno-gnu-linker-fpcc-struct-retu
Rn-fpic-fPIC-freg-struct-return-fshared-data-fshort-enums-fshort-d
Ouble-fvolatile-global-fverbose-asm



Overall Option)

-X language

Specify the language of the subsequent input file as language (instead of the default option obtained from the filename suffix ).
This option is applied to all subsequent input files until the next '-x' option. language is optional.
Values include 'C', 'Objective-C', 'c-header', 'c ++ ', 'cpp-output', 'cycler', and'
Extends er-with-cpp '.

-X none

Close any explicit description of the language, so process the subsequent files based on the filename suffix (as if they were never used
'-X' option ).

You can use the '-x' option (or
File name suffix) tells gcc where to start and uses the '-C','-S', or '-e' option to tell gcc where to end.
Some options (for example, '-x cpp-output-e') Make gcc do nothing.

-C

Compile or compile the source file, but it is not connected. The Compiler outputs the target file corresponding to the source file.

By default, GCC uses '. o' to replace the source file name suffix'. C', '. I', '. s', and so on to generate the target file
Component name. You can use the-o option to select another name.

GCC ignores any unrecognized input files following the-c option (they do not need to be compiled or compiled ).

-S

After compilation, it is stopped without Assembly. For each input non-assembly language file, the output file is an assembly language file.
Parts.

By default, GCC replaces the source file name suffixes '. C','. I 'with'. o' to generate the target file name.
You can use the-o option to select another name.

GCC ignores any input files that do not need to be compiled.

-E

The pre-processing is stopped without compilation. The pre-processing code is sent to the standard output.

GCC ignores any input files that do not require preprocessing.

-O file

Specifies the output file as file. This option does not care about the output produced by GCC, whether it is an executable file or a target file.
, Assembly file or pre-processed C code.

Because only one output file can be specified, it is meaningless to use the '-O' option when compiling multiple input files, unless
Output an executable file.

If the '-O' option is not used, the default output result is: the executable file is 'a. out', 'source. suffi
The target file of x' is 'source. o', the Assembly file is 'source. s', and the pre-processed C source code is sent to
Quasi-output.

-V

(In a standard error) display the command for executing the compilation phase, and display the compiler driver, Preprocessor, Compiler
.

-Pipe

Use pipelines instead of temporary files for communication between different phases of the compilation process. This option is unavailable on some systems.
Because the assembler of those systems cannot read data from the pipeline. The GNU assembler does not have this problem.


LANGUAGE OPTIONS)

The following options control the C "dialect" acceptable to the compiler ":

-Ansi

Supports ANSI-compliant C Programs.

In this way, some features that are incompatible with ansi c in gnu c will be disabled, such as asm, inline, and typeof keywords.
, As well as predefined macros such as unix and vax that indicate the current system type, enabling both undesirable and rare
Use the ANSI trigraph feature and disable '$' from being part of the identifier.

Although the '-ansi' option is used, the following Optional keywords: _ asm __, _ extension __, _ in
Line _ and _ typeof _ are still valid. Of course you will not use them in ansi c Programs, but you can use them
Put it in the header file, because during compilation of programs containing these header files, the '-ansi' option may be specified. Another
Some predefined macros, such as _ unix _ and _ vax __, are always valid regardless of whether the '-ansi' option is used.

The '-ansi' option does not automatically reject compilation of non-ANSI programs unless the '-pedantic' option is added '-
Ansi' option supplement.

When the '-ansi' option is used, the Preprocessor predefines A _ STRICT_ANSI _ macro. Some header files are off
Note This macro to avoid declaring some functions or defining some macros which are not called by ANSI standards.
In this way, programs using these names will not be disturbed elsewhere.

-Fno-asm

Do not use asm, inline, or typeof as keywords. Therefore, these words can be used as identifiers. Use _ asm __,_
_ Inline _ and _ typeof _ can replace them. '-ansi' implicitly declares '-fno-asm '.

-Fno-builtin

Built-in functions (built-in function) that do not start with two underscores are not accepted. Currently, the affected functions include:
_ Exit, abort, abs, alloca, cos, exit, fabs, labs, memcmp, memcpy, sin, s
Qrt, strcmp, strcpy, and strlen.

The '-ansi' option can block alloca and _ exit from being built-in functions.

-Fhosted

Compiled by the host environment. It implicitly declares the '-fbuiltin' option and warns of incorrect main function declaration.


-Ffreestanding

Compiled in an independent environment. It implicitly declares the '-fno-builtin' option and has no special requirements for the main function.


All the standard libraries in the host environment (hosted environment) are available. The main function returns an in
A typical example is that there are almost all programs except the kernel. The corresponding independent environment (freestanding en)
Vironment) there is no standard library, and the program entry is not necessarily the main, the most obvious example is within the operating system
Core. For details, refer to the latest documents on the gcc website)

-Fno-strict-prototype

For function declaration without parameters, for example, 'int foo (); ', it is processed in the C style-that is, the number of parameters or
Type. (Only for C ++). Normally, such function foo means that the parameter is null in C ++.

-Trigraphs

The support for ansi c trigraphs. '-ansi' option implicitly declares '-graphs '.

-Traditional

Attempts to support some aspects of the traditional C compiler. For details, see the gnu c manual. We have removed the detailed list from here.
In this way, when the content is outdated, people will not blame us.

Except one thing: For C ++ programs (not C), the '-traditional' option brings an additional effect, allowing
This value is assigned. It has the same effect as the '-fthis-is-variable' option.

-Traditional-cpp

Attempts to support some aspects of the traditional C Preprocessor. In particular, the content about the pre-processor mentioned above, but not the package
Include other effects of the '-traditional' option.

-Fdollars-in-identifiers

The '$' character (only for C ++) can be used in identifier. You can specify '-fno-dollar
The s-in-identifiers option explicitly prohibits the '$' character. (gnu c ++ allows'
$ ', But not all systems .)

-Fenum-int-equiv

Implicit conversion from int to enumeration is allowed (only for C ++). Under normal circumstances, gnu c +
+ Conversion from enum to int is allowed, but not vice versa.

-Fexternal-templates

Generates a small amount of code for the template declaration (template declaration only ).
Template function, which generates a copy only at the place where they are defined.
This option, you must mark '# pragma implementation' (Definition
) Or '# pragma interface' (Declaration ).

When the program is compiled using '-fexternal-templates', the template instantiation is complete.
Is an external type. You must make the required instance appear in the implementation file. You can use typedef to implement this.
Which references each instance. If the default option '-fno-external-tem is used during compilation
Plates, all template instances are explicitly set as built-in.

-Fall-virtual

All possible member functions are virtual functions by default. All member functions (except constructors and new or delet
E Member operator) is considered as a virtual function of the class.

This does not indicate that each call to a member function is performed through the internal virtual function table. In some cases, the compiler can determine
You can call a virtual function directly.

-Fcond-mismatch

The type of the second and third parameters of the allowed conditional expressions does not match. The value of this expression is void.

-Fthis-is-variable

This value can be assigned only to C ++. After the User-Defined free storage management mechanism is merged to C ++, the value can be assigned.
This is out of date. Therefore, by default, the class member function assigns an invalid value to this operation.
However, for backward compatibility, you can use the '-fthis-is-variable' option to make this operation valid.

-Funsigned-char

Define a char as an unsigned char.

Each machine has its own default char type, either unsigned char or signed char.


Ideally, a portable program should always use signed char or
Unsigned char. But many programs have already written only simple char, and expect this to be a signed number (or
The number of unsigned programs, depending on the program's target machine). This option, and its assigned options, make
Such a program works on the corresponding default value.

The char type should always be clearly defined as signed char or unsigned char, even if it represents
Is exactly the same.

-Fsigned-char

Define char as a signed type, just like signed char.

This option is equivalent to '-fno-unsigned-char', which is the negative form of'-funsigned-
The opposite option of char. Similarly, '-fno-signed-char' is equivalent to '-funsigned-char '.

-Fsigned-bitfields

-Funsigned-bitfields

-Fno-signed-bitfields

-Fno-unsigned-bitfields

If the 'signe' or 'unsigne' modifier is not explicitly declared, these options are used to define a signed-bit domain (B
Itfield) or a non-Signed bit field. By default, bit fields are signed because they inherit the basic integer type.
, Such as int, is a signed number.

However, if the '-traditional' option is specified, the bit field is always an unsigned number.

-Fwritable-strings

Store string constants in writable data segments without special treatment. This is to be compatible with some old programs.
Assume that the String constant is writable. The '-traditional' option also has the same effect.

Tampering with string constants is a very bad idea; ''constant ''should be a constant.



Preprocessor Option)

The following options are for the C Preprocessor, which is used to process the C source file before official compilation.

If the '-e' option is specified, GCC only performs preprocessing. Some of the following options must be included with the'-e' option.
It makes sense because their output results cannot be used for compilation.

-Include file

Before processing a regular input file, first process the file. The result is that the file content is compiled first.
Any '-d' and'-U' options on the command line are always processed before '-include file', regardless of whether they are in the command line.
The Order on the rows. However, the '-include' and '-imacros' options are processed in writing order.

-Imacros file

Before processing a regular input file, you must first process the file but ignore the output.
The only effect of the '-imacros file' option is to make the macro definition in the file take effect.
Can be used for other input files. Before processing the '-immobilsfile' option, the Preprocessor first processes'-d'
And '-U' options, and do not care about their order on the command line. However, the'-include 'and'-imacros 'options
Processing in writing order.

-Idirafter dir

Add the directory dir to the second include path. If a header file is in the main include path (use '-I' to add the path
.

-Iprefix prefix

Specify the prefix as the prefix of the '-iwithprefix' option.

-Iwithprefix dir

Add the directory to the second include path. The directory name is merged by prefix and dir. Here the prefix is
The '-iprefix' option is specified.

-Nostdinc

Do not search for the header file in the standard system directory. Only search for the directory specified by the '-I' option (and the current directory, if
Suitable ).

With the '-nostdinc' and '-I-' options, you can restrict the inclusion file search to explicitly specified directories.


-Nostdinc ++

Do not search for header files in the C ++ standard directory, but still search for other Standard Directories.
+ + .)

-Undef

Do not predefine any non-standard macros (including system structure flag ).

-E

Only run C Preprocessor. pre-process all specified C source files and send the results to standard output or specified output files.


-C

Tell the Preprocessor not to discard comments. Use it with the '-e' option.

-P

Tell the Preprocessor not to generate the '# line' command. Use it with the'-e' option.

-M [-MG]

Tells the Preprocessor to output a rule suitable for make to describe the dependencies of each target file.
Source file. The Preprocessor outputs a make rule. The target of the rule is the target of the source file.
File Name, dependency is all files referenced by '# include in the source file. The generated rules are as follows:
It is a single row, but if it is too long, use '\'-linefeed to continue to multiple rows. The rule is displayed in the standard output and does not generate a prefix
C program.

'-M' implies the'-e' option.

'-MG' requires that the missing header files be treated as existing files, and that they are in the same directory as the source file.
Must be used with the '-m' option.

-MM [-MG]

It is similar to the '-m' option, but the output result only involves the user header file, like this' # include file "'. Ignore the system
General header files, such as '# include '.

-MD

Similar to the '-m' option, but the dependency information is output to the file. The file name is indicated '.
O 'is replaced with'. D' to generate. At the same time, the specified compilation task is continued. '-md' is not like'-m' to prevent normal compilation.
Translation Task.

The Mach utility 'md' can merge '. d' files to generate a single dependent file suitable for the 'make' command.


-MMD

Similar to the '-md' option, the output only involves the user header file, ignoring the system header file.

-H

Besides other common operations, GCC displays referenced header file names.

-Aquestion (answer)

If the pre-processor performs a condition test, such as '# if # question (answer)', this option can be Assert)
The answer to question is answer.-A-'disabling standard assertions that are generally used to describe the target machine.

-Dmacro

Define macro. The macro content is defined as the string '1 '.

-Dmacro = defn

Define the macro content as defn. All '-d' options on the command line are processed before'-U' options.

-Umacro

Canceling the macro. '-U' option is processed after all'-d' options, but takes precedence over any '-include' or
'-Imacros' option.

-DM

Tells the Preprocessor to output a valid macro definition list (the macro definition is still valid at the end of preprocessing ).
Use the '-e' option.

-DD

Tells the Preprocessor to pass all macro definitions to the output end and display them in the displayed order.

-DN

Similar to the '-dd' option, but ignore macro parameters or content. Only the' # define name is displayed at the output end.



ASSEMBLER OPTION)

-Wa, option

The option is passed to the assembler. If option contains commas, multiple options are split into commas.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.