GCC User Manual
Author: Clock 1. Introduction
The English version of the GCC compiler is very comprehensive, and the structure is also very perfect, but there is no Chinese version. I read the main content of the GCC compiler this time, the content of the manual is structured. Sex an understanding, it is considered necessary to organize this reading content and prepare for future work.
Since I read this English manual is only structural. Therefore, there are many places that don't look, so I can only write some part of this document. For the place where you need more understanding, you will add content to this document, and the content that needs to add is mainly compiled. Switch.
2. GCC function introduction
The GCC compiler completes the conversion of target code running from C, C , Objective-C, running on a specific CPU hardware (this is the task that needs to be completed).
The source files that GCC can process are divided into C, C , Objective-C, assembly language, etc. For these source files, labeled them with their suffix names. The suffix that GCC can handle is:
a. * .c * .c (C language)
b. * .cxx * .cc (C language)
c. * .m (object-oriented C)
d. * .i (pre-processed C language source file)
e. * .ii (pre-processed C language source file)
f. * .s * .s (assembly language)
h. * .h (header)
The target file can be:
a. * .o compiled target files
b. * .a library file
The compiler divides the task of compiling the target code into the following steps:
a. Preprocessing, the pre-processing command scan is completed;
b. Compile, compile the pre-processed results into compilation or target modules;
c. Compilation, edip the compiled results into the target code module on the specific CPU;
d. Connect, connect multiple target code modules to generate a large target module;
3. GCC switch
The GCC running switch is divided into 11 categories, which is the operation 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 operation of the four steps of the GCC in the "GCC function introduction", in the default, these four steps are executed, but when some global switch is given, these steps The execution will be stopped in one step, which creates intermediate results, for example, may simply need the result of the pre-processing in the middle or assembled files (such as the intended purpose to see how the assembly language on a CPU).
3.1.1. -X Language
For the source file, what language is written, can be launched by the subscripted suffix, or this switch can also be used. Specifying the language written in the input file, Language can be the following
a. c
b. Objective-c
c. c-header
d. c
E.cpp-output
F.assembler
G.assembler-with-cpp
3.1.2.-x None
Turn off the -x switch introduced in the previous section.
3.1.3. -C
Compile to the source file target code, do not connect the action.
3.1.4. -S
Compile the source file into assembly code, do not make assembly and connections.
3.1.5. -E
The result output only after the source file is preprocessed. Do not do compile, assembly, and connection action.
3.1.6. -O file
Indicates the output file name is file.
3.1.7. -V
The output information of the entire compilation process is printed.
3.1.8.-Pipe
Since GCC's work is done, it is necessary to generate temporary files during the process, and use -pipe to replace temporary files with pipelines. 3.2. Language Options
Used to handle and language-related control switches.
3.2.1.-ANSI
This switch allows the GCC compiler to turn off all GNU compiler features, allowing your programs to be compatible with ANSI standards.
In addition to the above switches, there are still many language-related switches. If you encounter it in future work, it is not too late! 3.3. Preprocessor Options
The switches used to control the pre-processes.
3.3.1. -Include file
Before compiling, put the file into it, which is equivalent to adding a #include
3.3.2. -Imacros file
Like -inClude file. However, this document is only used in specific compilation, and the value is used to define a macro in the File file.
3.3.3. -Nostdinc
Remove the standard C language header file search path in the file path of Include, such as the stdio.h file is placed under the standard header file search path.
3.3.4. -Nostdinc
Also, just remove the header file search path of the standard C language.
3.3.5. -C
Use the-E parameter. Let the results after pretreatment, keep your comment, let people read it better.
3.3.6. -Dmacro
Define MacRo as a string '1'.
3.3.7. -Dmacro = DEFN
Define MACRO as DEFN.
3.3.8. -Umacro
Cancel the definition of Macro.
In addition to the above switches, there are still many pretreatment related switches. If you encounter it in the future work, it is not too late!
3.4. Assembler Option
The switch used to control assembly behavior.
3.4.1. -Wa, option
Give Option as the switch to the assembler. If there is a comma in Option, it is handled as a few lines.
3.5. Linker Options
Switch options used to control the connection process.
3.5.1. Object-file-name
3.5.2. -Llibrary
Connect the library file switch. For example, -LUGL, the program is connected to the libugl.a file.
3.5.3. -Lobjc
This switch is used in library file processing of object-oriented C language files.
3.5.4. -Nostartfiles
Do not connect the system-related startup code when the connection is connected.
3.5.5. -Nostdlib
Do not connect the system-related startup files and system-related libraries when they are connected.
3.5.6. -Static
A dynamic connection is supported on some systems, this switch does not allow dynamic connections.
3.5.7. -Shared
Generate a target module that can be shared by other programs.
There are still some connections related to the switch, and then make it again.
3.6. Directory Related Switch (Directory Options)
Used to define the switch related to the directory operation.
3.6.1. -IDIR
Macro INCLUDE needs to search for a directory.
3.6.2.-i-
Similar to the -i switch.
3.6.3.-LDIR
The path to the library file (* .a).
There are still a lot of switches related to the directory, and it needs to be added later.
3.7. Warning switch (WARNING OPTIONS)
Switches related to warning processing.
3.7.1.-fsyntax-only
Only the syntax errors in the code are checked, but there is no output.
3.7.2. -W
Prohibit all warning information to print out.
3.7.3. -Wno-import
It is forbidden to warn the macro #import.
3.7.4. -Pedantic
3.7.5. -Pedantic-errors3.7.6. -W
There are many switches related to warning processing, and then make it again.
3.8. Debugging Options
3.8.1. -g
Open the debugging switch and make the compiled target file with debug information.
There are still many switches related to debugging processing, and then make up.
3.9. Optimization Switch (Optimization Options)
-O1 -O2 -O3 -O0, these switches control optimized strength, and -O3 is the strongest.
3.10. Target Switch (Target Options)
3.10.1. -B Machine
In some cases, the target code compiled by the GCC compiler is not running on the machine running this compile action, which is another machine. This compile is called cross-compilation, which is used to run the final target code. Machine is used to indicate the type of target machine.
3.10.2. -V Version
The Version parameters are used to represent the version of the number of functions used to tell the compiler to use it.
3.11. CPU-related switch (Machine Dependent Options)
More, it is also used when cross-compilation. talk about it later.
3.12. Code Generation Option **************************************************** *********************************************************** **
GCC Use Guide to use syntax:
GCC [option | filename] ... G [option | filename] ...
The option when Option is used for GCC (will be detailed later), and FileName is a file that wants to process GCC.
Description:
This COMPILER of C has been integrated with related programs that generate new programs. Generating a new procedure requires four phases: pretreatment, compile, assembly, link, and these two compilers can process the input files different stages. Although the extension of the original program can be used to resolve the language used by the original program code, the different Compiler, its preset handler is different:
The GCC presets the file via the pre-processed (extension-name .i) as a C language, and is handled in C in C in C.
G defaults to the C language via the pre-processed (extension .i) and processes the program linkage to C connection mode.
The extension of the original program code indicates the language used by the written program used, and the corresponding method of processing:
.C C original program; pretreatment, compilation, assembly .c C original program; pretreatment, compilation, assembly .cc C original program; pre-processing, compilation, assembly .cxx C original program; pretreatment, compilation, assembly .m Objective-c original program; pretreatment, compilation, assembly .i has been pre-processed C original program; compilation, assembly .ii has passed the C original program that has been pre-processed; compile, compile. S-combined language original program; assembly .s Combined language original program; pretreatment, assembly .h pre-processing file (header file); (not often in the instruction line)
Other extensions have been processed by links, usually: .o Object File .a Archive File
Unless the compilation process has an error, "link" must be the final stage of a new program. However, you can also stop one of the four phases in four phases of options such as -c, -s or -e. In the coupling phase, all the .o files, libraries, and other files that cannot be identified from the original code (including the Object File that are not extended, as well as the extension .a), including .a .a archive file) Both will be handed over (in the instruction line as the parameter passing to the connection program).
Option:
Different options must be separated: For example, `-dr 'This option is different from` -d -r'.
Most of the larger `-f 'and` -w' options have two forms: -fname and -fno-name (or -wname and -wno-name). The following is only listed in the non-preset form.
The following is a summary of all options. Classified in the form. The meaning of the option will also make another section.
General (rough, commonly used) option -c -s -e -o file -pipe -v -x loguage
Program Language Options - Mismi-Fall-Virtual -fcond-Mismatch -fdollar-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 -traditional-cpp-trigraphs
WARNING Options - FSYNTAX-OnLY -PEDANTIC -PEDANTIC-ERRORS -W -W -WALL-WAGGREGATE-RETURN -WCAST-ALIGN -WCAST-QUAL -WCHAR-SUBScript -wcomment -wconversion -wenum-clamp -werror -wformat -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
Error option -a -dletters -fpretend-float -g -glevel -gcoff -gxcoff -gxcoff -gdwarf -gdwarf -Gstabs -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-INSS - FSCHEDULE-INS2 -FSTRENGTH-REDUCE-FTHREAD-JUMPS -FUNROLL-All-loops -Funroll-loops -o -o2
Pretreatment Options - OAASSERTION -C -DD -DM -DN -DMACRO [= DEFN] -E-H -IDIRAFTER DIR -INCLUDE FILE-IMCROS file -iprefix file -iwithprefix dir -m -md -mm -mmd -nostdinc -P -Umacro -undef
Assembler Options - WA, Option
Connection program - LLIBRARY -NOSTARTFILES -NOSTDLIB -STATIC -SHARED -SYMBOLIC -XLINKER OPTION -WL, OPTION -U SYMBOL
Directory Options - BPREFIX -IDIR -I- -LDIR
Target Options -b Machine -V Version
With machine (platform) related options M680x0 options -m68000 -m68020 -m68020-40 -M68030 -MBITFIELD -MC68000 -MC68020 -MFPA -MNOBITFIELD-MRTD -MSHORT -MSOFT-FLOAT
VAX OPTIONS -MG-MGNU -Munix
SPARC OPTIONS -MEPILOGUE-MFPU -MHARD-FLOAT-MNO-FPU -MNO-EPILOGUE -MSOFT-FLOAT -MSPARCLITE -MV8 -MSUPERSPARC -MCYPRESS
CONVEX OPTIONS -MARGCOUNT -MC1 -MC2 -MNOARGCOUNT
AMD29K Options -m29000 -m29050 -mbw -mdw -mkernel-registers -mlarge -mnbw -mnodw -msmall -mstack-check -muser-registersM88K 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 -MOPTIMIMIZE-ARG-Area-MSerialize-Volatile-MVR4 -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 -LIN-LINE-MUL-MMINIMUM-FP-block-mminhc -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-MNO-MNO- MIPS-TFILE-MMIPS-TFILE-MSOFT-FLOAT-MHARD-FLOAT-MABICALLS -MNO-ABICALLS-MHALF-PIC -MNO-HALF-PIC -G Num -NOCPP
I386 OPTIONS -M486 -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-Calls -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-align-mald-aligndec alpha options -mfp -regs-malo-fp-regs-malo-soft-float-msoft-float
System v options -g -qy -qn-yp, paths -ym, dir
Code Generation Options -fcall-Saved-Reg-Fcall-use-reg -ffixed-regall-limited-size-directive -fnonnull-objects -fno-common -fno-ident -fno-gnu-linker -fpcc-struct-return-FPCC-STRUCT-RETURN - FPIC-FPIC -FREG-STRUCT-RETURNO -FSHARED-DATA-FSHORT-ENUMS -FSHORT-DOUBLE -FVOLATILE -FVOLATILE-GLOBAL -FVERBOSE-ASM
PRAGMAS Two `#pragma 'directives are supported for GNU C , to permit using the same header file for two purposes: as a definition of interfaces to a given object class, and as 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 (backup copies certain information 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 class definitions. You can use this pragma to avoid such duplication. When a header file containing `#pragma interface 'is included in a compilation, this auxiliary information will not be generated (unless the main input source file it- self uses `#pragma implementation '). Instead, the object files will contain 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 included header file, in turn, should Use `#pragma interface '. Backup Copies of Inline MEM- BER FUNCTIONS, Debugging Information, And The IN- TERNAL TABLES USED TO IMPLEMENT VIRTUAL FUNCTION SILES.
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 single header file into multiple implementation files.
Document Description File.c C Source File File.h C Header (Preprocessor) File File.i Pretreatable C Source File File.c 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 / cc1 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 / incrude 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).