GCC User Manual

Source: Internet
Author: User
GCC User Manual

[Reprinted] GCC user manual Chinese Version

Author: Clock
 
1. Preface

The GCC Manual (GCC manual) version is very comprehensive and well-structured, but there is no Chinese version. I read the main contents of the GCC compiler this time, I have a structural understanding of the content of the manual and think it is necessary to sort out the content of this reading to prepare for future work.

Because I read this English Manual only structurally. Therefore, I have not read many of them, so I can only write some of the content in this document. I will add more content to this document for further details, the main content to be added is the compiler's various switches.

2. GCC features

The GCC compiler converts source files such as C, C ++, and objective-C to the target code running on a specific CPU hardware (this is a task that any compiler needs to complete ).

The source files that GCC can process include C, C ++, objective-C, and assembly language. These source files are marked with their extension names. The suffixes that can be processed by GCC include:

A. *. C *. C (c)

B. *. cxx *. CC (C ++ LANGUAGE)

C. *. m (Object-Oriented C)

D. *. I (C source file after preprocessing)

E. *. II (pre-processed C ++ source file)

F. *. S *. S (assembly language)

H. *. H (header file)

The target file can be:

A. *. o the target file after the connection is compiled

B. *. A library file

The compiler divides the task of generating the target code into the following four steps:

A. Pre-processing: the pre-processing command is scanned and processed;

B. Compile and compile the pre-processing results into an assembly or a target module;

C. Compile and compile the compiled results into the target code module on a specific CPU;

D. connect multiple target code modules to generate a large target module;

3. GCC Switch

The GCC operation switch is divided into 11 categories, which control the running of the GCC program from 11 aspects to achieve specific compilation purposes.

3.1. Global switch (overall options)


The global switch is used to control the running of GCC in four steps in "GCC function Introduction". By default, all the four steps are executed, however, after some global switches are specified, these steps are
Stop execution in one step, which produces intermediate results, for example, you may only need the pre-processing results or assembly files generated in the middle (for example, it is intended to see how to write the assembly language on a CPU ).

3.1.1.-X Language

You can use the suffix of the file name to indicate the language in which the source file is written. Specifies the language in which the input file is written. The language can be the following content:

A. c

B. Objective-C

C. C-Header

D. c ++

E. cpp-Output

F. Cycler

G. Cycler-with-CPP

3.1.2.-X none

Turn off the-x switch described in the previous section.

3.1.3.-C

Compile the source object code without any connection.

3.1.4.-S

Compile the source file into assembly code without assembly and connection.

3.1.5.-e

Only output the result after preprocessing of the source file. Do not compile, assemble, or connect.

3.1.6.-o file

Specifies that the output file name is file.

3.1.7.-V

Print the output information of the entire compilation process.

3.1.8.-Pipe

Since GCC is completed in several steps, you need to generate a temporary file during the process. Use-pipe to replace a temporary file with a pipe.

3.2. language related switch (language options)

It is used to process language-related control switches.

3.2.1.-ANSI

This switch enables the GCC compiler to turn off all GNU Compiler features so that your program can be compatible with the ANSI standard.

In addition to the above switches, there are many language-related switches. If you encounter them in your future work and study, it will be too late! 3. Preprocessor options)

Used to control the toggle set by preprocessing.

3.3.1.-include file

Before compilation, include the file, which is equivalent to adding a # include <File> statement at the beginning of all the compiled source files ".

3.3.2.-imacros File

The same as-include file. However, this file only works when it is compiled. Therefore, the value is used to define the macro in the file.

3.3.3.-nostdinc

Remove the Standard C header file search path from the file path of the search include. For example, stdio. h file is stored in the standard header file search path.

3.3.4.-nostdinc ++

Just remove the header file search path in the Standard C ++ language.

3.3.5.-C

Use with-e parameters. Let the pre-processing results retained comments to make it easier to read.

3.3.6.-dmacro

Define macro as the string '1 '.

3.3.7.-dmacro = defn

Define macro as defn.

3.3.8.-umacro

Cancels the definition of Macro.

In addition to the above switches, there are many pre-processing related switches. If you encounter any problems in your future work and study, it will not be too late!

3.4. assembler Option)

The switch used to control assembly behavior.

3.4.1.-Wa, Option

Send option as a switch to the assembler. If the option contains a comma, it is processed as several rows.

3. 5. Linker Options)

The switch option used to control the connection process.

3.5.1. Object-file-name

3.5.2.-llibrary

Connection Library File switch. For example,-lugl connects the program to the libugl. A file.

3.5.3.-lobjc

This switch is used to process the library files of object-oriented C language files.

3.5.4.-nostartfiles

During the connection, the System-related startup code is not connected.

3.5.5.-nostdlib

During the connection, do not connect the system-related startup files to the System-related libraries.

3.5.6.-static

Some systems support dynamic connections. This switch does not allow dynamic connections.

3.5.7.-shared

Generate shared target Modules connected by other programs.

There are still some connection-related switches, which will be supplemented later as needed.

3. 6. Directory related switch (directory options)

Defines the switches related to directory operations.

3.6.1.-Idir

Macro include directory to be searched.

3.6.2.-I-

Similar to the-I switch.

3.6.3.-ldir

Search for the path of the library file (*..

There are many other directory-related switches that need to be added later.

3.7. Warning switch (warning options)

The switch related to the warning processing.

3.7.1.-fsyntax-only

Only check for syntax errors in the code, but there is no output.

3.7.2.-W

Disable printing of all warning information.

3.7.3.-wno-Import

Do not warn macro # import.

3.7.4.-pedantic

3.7.5.-pedantic-Errors

3.7.6.-W

There are also a lot of switches related to warning processing, and they will be supplemented later.

3.8. debug switch (debugging options)

3.8.1.-G

Turn on the debug switch to enable debugging information for the compiled target file.

There are also many debugging-related switches that will be supplemented later.

3.9. Optimization Options)

-O1-O2-O3-O0, these switches control the optimized intensity respectively, and-O3 is the strongest.

3.10. Target options)

3.10.1.-B Machine

Sometimes, the target Code Compiled by the GCC compiler is not run on the machine that runs this compilation action, but another machine. This compilation is called cross compilation, the machine used to run the final target code is called the target machine, which is used to specify the type of the target machine.

3.10.2.-V version

It is used to tell the compiler how many versions it uses, and the version parameter is used to represent the version.

3.11. machine dependent options)

It is also used in cross-compilation. Later.

3.12. Code Generation Options)
 
**************************************** **************************************** ************

GCC User Guide
Syntax:

GCC [Option | filename]...
G ++ [Option | filename]...

Where option is the option used for GCC (which will be detailed later ),
Filename is the object to be processed with GCC.

Note:

This C and C ++ compiler have integrated the related programs that generate new programs. Production
A new program requires four stages: preprocessing, compilation, assembly, and linking.
Compilers can process input files in different stages. Although the extension of the original program is
It is used to distinguish the language used to write the original program code, but different compiler, its preset Processing
Different programs:

GCC presets files that have been preprocessed (with the extension. I) to C language, and
The connection phase is processed in C connection mode.

G ++ defaults that files that have been preprocessed (with the extension. I) are in the C ++ language.
The sequential connection phase is processed in the C ++ connection mode.

The extension of the original code indicates the language used for programming and the corresponding
Management Method:

Original. C program; preprocessing, compilation, and assembly
Original. c ++ program; preprocessing, compilation, and assembly
. Cc c ++ original program; preprocessing, compilation, and assembly
. Cxx C ++ original program; preprocessing, compilation, and assembly
. M objective-C original program; preprocessing, compilation, assembly
. I original C program that has been preprocessed; compilation and assembly
. II Original C ++ program that has been preprocessed; compilation and assembly
Original program of. s combination language; Assembly
Original program of. s combination language; preprocessing and compilation
. H pre-processing file (header file); (not frequently displayed in the command line)

Files with other extensions are processed by the link program, usually including:

. O object file
. A archive file

Unless an error occurs during the compilation process, the "Link" must be the most
Later Stage. However, you can also set the entire process from
Phase. In the connection phase, all
. O files, libraries, and other files that cannot identify attributes from the file name (including files that do not use. o
Object file with the extension and archive file with the extension.)
It is handled by the link program (the files in the command line are passed as parameters of the link Program
Link program ).

Option:

Different options must be separated. For example, the '-write' option is larger than the'-D-R' option.
Different.

Most of the '-F' and'-W' options have two forms:-fname and
-Fno-Name (or-wname and-wno-name ). Only the non-preset ones are listed below
Format.

The following is a summary of all options. In the form. The meaning of the option will be explained in another section.
Ming.

General (rough, common) Options
-C-s-e-o file-pipe-v-x Language

Program language options
-ANSI-fall-Virtual-fcond-Mismatch
-Fdollars-in-identifiers-fenum-int-equiv
-Fexternal-templates-fno-ASM-fno-builtin
-Fno-strict-prototype-fsigned-bitfields
-Fsigned-Char-fthis-is-Variable
-Funsigned-bitfields-funsigned-Char
-Fwritable-strings-traditional-CPP
-Trigraphs

Warning options during compilation
-Fsyntax-only-pedantic-errors-w
-Wall-waggregate-return-wcast-align-wcast-Qual
-Wchar-subscript-wcomment-wconversion
-Wenum-clash-werror-wformat-wid-clash-Len
-Wimplicit-winline-wmissing-prototypes
-Wmissing-declarations-wnested-externs-wno-Import
-Wparentheses-wpointer-Arith-wredundant-decls
-Wreturn-type-wshadow-wstrict-prototypes-wswitch
-Wtemplate-debugging-wtraditional-wtrigraphs
-Wuninitialized-wunused-wwrite-strings

Debugging options
-A-dletters-fpretend-float-g-glevel-gcoff
-Gxcoff +-gdwarf +-gstabs +
-Ggdb-p-PG-save-temps-print-file-name = library
-Print-libgcc-file-name-print-prog-name = Program

Optimization Options
-Fcaller-saves-fcse-Follow-Jumps-fcse-Skip-Blocks
-Fdelayed-branch-felide-constructors
-Fexpensive-optimizations-ffast-math-ffloat-store
-Fforce-ADDR-Fforce-Mem-Finline-Functions
-Fkeep-inline-functions-fmemoize-lookups
-Fno-default-inline-fno-defer-pop
-Fno-function-CSE-fno-inline-fno-peephole
-Fomit-frame-pointer-frerun-CSE-after-Loop
-Fschedule-insns-fschedule-insns2
-Fstrength-reduce-fthread-Jumps-funroll-all-Loops
-Funroll-loops-o-O2

Preprocessing options
-Aassertion-C-dd-DM-DN-dmacro [= defn]-e-H
-Idirafter Dir-include file-imacros file-iprefix
File-iwithprefix Dir-m-MD-mm-MMD-nostdinc-P
-Umacro-UNDEF

Assembler options
-Wa, Option

Link Program Options
-Llibrary-nostartfiles-nostdlib-static-shared
-Symbolic-xlinker option-wl, option-u symbol

DIRECTORY Options
-Bprefix-Idir-I-ldir

Target options
-B machine-V version

Machine (Platform) related options
M680x0 options
-M68000-m68020-m68020-40-m68030-m68040-m68881
-Mbitfield-mc68000-mc68020-MFPA-mnobitfield
-MRTD-mshort-msoft-float

VAX options
-Mg-mgnu-munix

Iscsi options
-Mepilogue-mfpu-mhard-float-MnO-FPU
-MnO-epilogue-msoft-float-msparclite-mv8
-Msupernames-mcypress

Convex options
-Margcount-mc1-MC2-mnoargcount

Amd29k options
-M29000-m29050-MBW-MDW-mkernel-registers
-Mlarge-mnbw-mnodw-msmall-mstack-Check
-Muser-registers

M88k options
-M88000-m88100-m88110-mbig-pic
-Mcheck-Zero-division-mhandle-large-shift
-Midentify-revision-MnO-check-Zero-Division
-MnO-OCs-debug-Info-MnO-OCs-frame-Position
-MnO-optimize-Arg-area-MnO-serialize-volatile
-MnO-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 options
-MCALL-Lib-Mul-MFP-Arg-in-fpregs-MFP-Arg-in-Gregs
-Mfull-FP-blocks-mhc-struct-return-Min-line-Mul
-Mminimum-FP-blocks-mnohc-struct-return

MIPs options
-Mcpu = CPU type-mips2-mips3-mint64-mlong64
-Mlonglong128-mmips-as-MGAs-mrnames-MnO-rnames
-Mgpopt-MnO-gpopt-mstats-MnO-stats-mmemcpy
-MnO-memcpy-MnO-MIPS-tfile-mmips-tfile
-Msoft-float-mhard-float-mabicils-MnO-abicils
-Mhalf-pic-MnO-half-pic-G num-nocpp

I386 options
-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-mlong-CILS-mdisable-fpregs
-Mdisable-indexing-mtrailing-colon

I960 options
-Mcpu-type-mnumerics-msoft-float
-Mleaf-procedures-MnO-leaf-procedures-mtail-call
-MnO-tail-call-mcomplex-ADDR-MnO-complex-ADDR
-Mcode-align-MnO-code-align-mic-compat
-Mic2.0-compat-mic3.0-compat-MASM-compat
-Mintel-ASM-mstrict-align-MnO-strict-align
-Mold-align-MnO-old-align

DEC Alpha options
-MFP-regs-MnO-FP-regs-MnO-soft-float-msoft-float

System V Options
-G-QY-Qn-YP, paths-ym, Dir

Code Generation Options
-Fcall-saved-reg-fcall-used-reg-ffixed-Reg
-Finhibit-size-Directive-fnonnull-objects
-Fno-common-fno-Ident-fno-GNU-linker
-Fpcc-struct-return-FPIC
-Freg-struct-returno-fshared-data-fshort-enums
-Fshort-double-fvolatile-Global
-Fverbose-ASM

Pragmas
Two '# pragma' ctictives are supported for gnu c ++,
Permit using the same header file for two purposes: As
Definition of interfaces to a given object class, And
The full definition of the contents of that object class.

# Pragma Interface
(C ++ only.) use this directive in header files
That define object classes, to save space in most
Of the object files that use those classes. Nor-
Mally, local copies of certain information (Backup
Copies of inline member functions, debugging infor-
Mation, and the internal tables that implement vir-
Tual functions) must be kept in each object file
That includes des class definitions. You can use this
Pragma to avoid such duplication. When a header
File ining '# pragma interface' is supported in
A compilation, this auxiliary information will not
Be generated (unless the main input source file it-
Self uses '# pragma implementation'). Instead,
Object files will contain in references to be resolved
At link time.

# Pragma implementation

# Pragma implementation "objects. H"
(C ++ only.) Use This pragma in a main input file,
When you want full output from included Header
Files to be generated (and made globally visible ).
The encoded header file, in turn, shocould use
'# Pragma interface'. backup copies of inline mem-
Ber functions, debugging information, and the in-
Ternal tables used to implement virtual functions
Are all generated in implementation files.

If you use '# pragma implementation' with no argu-
Ment, it applies to an include file with the same
Basename as your source file; for example, in
'Allclass. CC', '# pragma implementation' by itself
Is equivalent to '# pragma implementation
"Allclass. H" '. Use the string argument if you want
A single implementation file to include code from
Multiple header files.

There is no way to split up the contents of a sin-
GLE header file into multiple implementation files.

File description
File. C source file
File. h c header (Preprocessor) File
File. I pre-processed C source file
File. C ++ source file
File. cc c ++ source file
File. cxx C ++ source file
File. m objective-C source file
File. s assembly language file
File. O object file
A. Out link edited output
Tmpdir/CC * temporary files
Libdir/CPP Preprocessor
Libdir/PC3 compiler for C
Libdir/cc1plus compiler for C ++
Libdir/collect linker front end needed on some machines
Libdir/libgcc. a gcc subroutine library
/Lib/CRT [01n]. o start-up routine
Libdir/ccrt0 additional start-up routine for C ++
/Lib/libc. A standard C library, see man page intro (3)
/Usr/include standard directory for # include files
Libdir/include standard GCC directory for # include files
Libdir/g ++-include additional g ++ directory for # include

Libdir is usually/usr/local/lib/machine/version.
Tmpdir comes from the environment variable tmpdir (default
/Usr/tmp if available, else/tmp ).

**************************************** *********
-O file
Specifies the output file name. This option is not required during compilation into the target code. If file is not specified, the default file name is A. Out.

-C
Compile only without Link

-Dfoo = bar
Define the pre-processing macro Foo in the command line, and its value is bar

-Idirname
Add dirname to the search directory list of the header file

-Ldirname
Add dirname to the search directory list of the library file. By default, GCC only links to the shared library.

-Static
Link the static library, that is, execute the static Link

-Lfoo
Link to the function library named libfoo

-G
Include standard debugging information in executable programs

-Ggdb
Only GNU Debugger can be included in an executable program so that up to two other items are information.

-O
Optimize compiled code

-On
Specify the code optimization level as N, O <= n <= 3

-ANSI
Standard Syntax of ANSI/iso c is supported to cancel parts that conflict with the standard in GNU syntax extension.
(But this option does not guarantee the generation of ANSI compatible code)

-Pedantic
All warnings listed in ANSI/iso c are allowed

-Pedantic-Errors
All errors listed in ANSI/iso c standards allowed

-Traditional
Supports kernighan & Ritchie C syntax (for example, defining a function using a legacy syntax). It does not matter if you do not know the meaning of this option.

-W
Disable all warnings. Do not use this option.

. Wall
All useful warnings that can be provided by GCC can be issued, or the specified warning can be marked with-W (warning ).

-Werror
Converts all warnings to errors to abort the compilation process when a warning occurs.

-Mm
Output a make-compatible list

-V
Displays the commands used in each step of the compilation process.

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.