[Introduction]
GCC and G ++ are respectively gnu c & C ++ Compilers
Gcc/g ++ requires a total of four steps for compiling.
1. pre-process and generate the. I file
Pre-processor CPP
2. Convert the pre-processed files into assembly languages to generate file. S.
Compiler egcs
3. a. o file is generated by means of compilation into the target code (machine code ).
Assembler
4. Connect the target code to generate an executable program
Connector LD
1. Overall options
-E
Only activate preprocessing. This does not generate a file. You need to redirect it to an output file.
Area.
Example usage:
Gcc-e hello. c> pianoapan.txt
Gcc-e hello. c | more
Let's take a look. A Hello word should also process 800 lines of code.
-S
Only activating preprocessing and compilation means compiling a file into assembly code.
Example usage
Gcc-s hello. c
It will generate the. s assembly code. You can view it in a text editor.
-C
Only activate preprocessing, compilation, and assembly, that is, he only makes the program into an OBJ file.
Example usage:
Gcc-C hello. c
It will generate the. o obj file
2. DIRECTORY Options
-Idir
When you use # include "file", GCC/g ++ first searches for the header you have specified in the current directory.
File. If not found, he will return to the default header file directory. If-I is used to specify the directory
Go back to the directory you created, and then find it in the regular order.
For # include, GCC/g ++ will go to the directory specified by-I and cannot find it.
Default header file directory search
-Include File
-I
Equivalent to "# include"
Contains a code. Simply put, a file can be used when another file is needed.
Using it to set the function is equivalent to using # include in the code
Example usage:
GCC hello. C-include/root/pianopan. h
-I-
Is to cancel the function of the previous parameter, so it is generally used after-Idir
-Idirafter dir
An error occurred while searching in the-I directory.
-Iprefix prefix
-Iwithprefix dir
Generally, if-I Directory Search fails, it will be searched under prefix + dir
-Ldir
Specify the path of the database to be searched during compilation. For example, you can use your own library to create a directory. Otherwise
The compiler will only find it in the standard library directory. This DIR is the directory name.
-Llibrary
Library Used during compilation
Example usage
Gcc-lcurses hello. c
Compile the program using the ncurses Library
3. debugging options
-G
Only the compiler generates debugging information during compilation.
-Maid
This option claims debugging information in stabs format, but does not include GDB debugging information.
-Gstabs +
This option claims debugging information in stabs format and contains additional debugging information for GDB only.
-Ggdb
This option will generate debugging information that can be used by GDB as much as possible.
-Glevel
Request to generate debugging information and use level to indicate the required information. The default level value is 2.
4. Link options:
-Static
This option disables dynamic libraries.
Advantage: The program runs independently of other libraries.
Disadvantage: large files
-Shared
(-G) This option will try to use the dynamic library, which is the default option.
Advantage: relatively small file generation
Disadvantage: The system must provide a dynamic library for running.
-Symbolic
When creating a shared target file, bind the reference to the global symbol.
Warn all references that cannot be parsed (unless you use the connection edit option '-xlinker-z
-Replace xlinker defs ).
Note: Only some systems support this option.
5. Error and alarm options
-Wall
This option is generally used to send all the useful warnings that GCC can provide. You can also use-W {warning} to mark the specified warning.
-Pedantic
All warnings listed in ANSI/iso c are allowed
-Pedantic-Errors
Errors listed in ANSI/iso c standards allowed
-Werror
Converts all warnings to errors to abort the compilation process when a warning occurs.
-W
Disable all warnings. Do not use this option.
6. Preprocessing options
-Dmacro
Equivalent to # define macro in C
-Dmacro = defn
Equivalent to # define macro = defn in C
-Umacro
Equivalent to # UNDEF macro in C
-UNDEF
Cancel definition of any non-standard macros
7. Other options
-O
Set the target name. By default, the GCC compiled file is a. Out, which is hard to hear. If you feel the same way with me, change it. Haha
Example usage
Gcc-O hello.exe hello. C (Oh, Windows is used to it)
Gcc-O hello. ASM-s hello. c
-O0
-O1
-O2
-O3
The compiler has four levels of optimization options.-O0 indicates no optimization,-O1 indicates the default value, and-O3 indicates the highest optimization level.
-FPIC
The compiler generates a location-independent target code. This Code is applicable to shared libraries ).
-FPIC
The compiler outputs a location-independent target code. This Code is applicable to dynamic connections, even if the branch needs to be transferred in a large range.
-V
Displays detailed compilation, assembly, and connection commands.
-Pipe
Using pipelines instead of temporary files during compilation may cause some problems when using non-GNU compilation tools.
Gcc-pipe-O hello.exe hello. c
-ANSI
Disable the incompatible features of ansi c in gnu c and activate the proprietary features of ansi c (including prohibiting some ASM inline typeof keywords, and preprocessing macros such as UNIX and VAX,
-Fno-ASM
This option is part of the feature that implements the ANSI option. It prohibits the use of ASM, inline, and typeof as keywords.
-Fno-strict-Prototype
It only works for G ++. With this option, G ++ does not explicitly describe the number and type of parameters for functions without parameters, instead of having no parameters. whether this parameter is used or not, GCC considers that there is no explicitly stated type for a function without parameters.
-Fthis-is-varialble
Is to align with the traditional C ++, you can use this when the general variable is used.
-Fcond-Mismatch
The second and third parameter types of conditional expressions do not match. The expression value is of the void type.
-Funsigned-Char
-Fno-signed-Char
-Fsigned-Char
-Fno-Unsigned-Char
These four parameters are used to set the char type and decide to set the char type to unsigned char (before
Two Parameters) or signed Char (the last two parameters)
-Imacros File
Extends the macro of the file to the input file of GCC/g ++. The macro definition does not appear in the input file.
-Nostdinc
Make the compiler no longer look for the header file in the system's default header file directory. It is generally used in conjunction with-I to specify the position of the header file.
-Nostdin C ++
The rule is not to be searched in the standard channels specified by G ++, but still in other paths. This option is used in the creation of libg ++ Library
-C
During pre-processing, do not delete the annotation information, which is generally used with-E. Sometimes the analysis program is very convenient to use.
-M
Generate file association information. You can use gcc-M hello. C to test all the source code that the target file depends on.
-Mm
It is the same as the one above, but it will ignore the dependency caused by # include.
-MD
It is the same as-M, but the output will be imported into the. d file.
-MMD
It is the same as-mm, but the output will be imported into the. d file.
-Wa, Option
This option is passed to the assembler; if there is a comma in the option, the option is divided into multiple options, and then passed to the assembler
-WL. Option
This option is passed to the connection program. If there is a comma in the option, the option is divided into multiple options and then passed to the connected program.
-X language filename
Set the language used by the file to make the suffix invalid. It will be valid for multiple later versions, that is, the root
It is agreed that the C language suffix is. C, and the C ++ suffix is. C or. cpp. If
You are very personal and decide that the suffix of your C code file is. Pig Haha, then you need to use this
Parameter. This parameter applies to all file names after it, unless the next parameter is reached.
.
Can I use the following parameters?
'C', 'Objective-C', 'c-header', 'c ++ ', 'cpp-output ',
'Referer', and 'referer-with-CPP '.
You can understand English.
Example usage:
Gcc-x C hello. Pig
-X none filename
Turn off the previous option, that is, let GCC automatically identify the file type based on the file name suffix
Example usage:
Gcc-x C hello. Pig-x none hello2.c