Differences and relationships between GCC and G ++
Both GCC and G ++ are GNU compilers.
1. For Files suffixed with. C, GCC treats it as a C program; G ++ treats it as a C ++ program;
2. For files with the. cpp suffix, both GCC and G ++ will be treated as C ++ programs.
3. In the compilation phase, G ++ calls GCC;
4. In the connection phase, G ++ is usually used to complete the process. This is because the GCC command cannot automatically connect to the library used by the C ++ program.
Gcc/g ++ requires a total of four steps for compiling.
1. preprocessing to generate. I files [pre-processor CPP] 2. convert the pre-processed file into an assembly language to generate the file. s [compiler egcs] 3. an assembly is generated into the target code (machine code. o file [assembler as] 4. connect the target code to generate an executable program [linker ld]
[Parameter Details]
-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
-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
-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.
-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.
-O
Specify the target name. The GCC compiled file is a. Out by default. If
You and I share the same feelings, get rid of it, haha
Example usage
Gcc-O hello.exe hello. C (Oh, Windows is used to it)
Gcc-O hello. ASM-s hello. c
-Pipe
Use pipelines to replace temporary files in compilation. When using non-GNU assembly tools, you may have some questions.
Question
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 disabling
Some ASM inline typeof keywords, as well as pre-processing macros such as UNIX and VAX,
-Fno-ASM
This option is part of the feature that implements the ANSI option. It does not allow the use of ASM, inline, and typeof
Keyword.
-Fno-strict-Prototype
It only works for G ++. With this option, G ++ considers all functions without parameters as not explicitly
Instead of having no parameters.
Whether this parameter is used or not, GCC will not explicitly describe functions without parameters.
Explicit type
-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)
-Include File
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 <FILENAME> in code
Example usage:
GCC hello. C-include/root/pianopan. h
-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.
Medium
-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
-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 <File>, the GCC/g ++ will go to the directory specified by-I, and the GCC/g ++ will not find it.
Default header file directory search
-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
-Nostdinc
Make the compiler no longer look for the header file in the system's default header file directory, which is generally used in conjunction with-I, clear
Specify the header file location
-Nostdin C ++
It is specified that the search is not in the standard path specified by G ++, but is still in another path. This option is created
Libg ++ library usage
-C
During pre-processing, do not delete the annotation information, which is generally used with-E. Sometimes the analysis program uses this
Convenient
-M
Generate file association information. Contains all source code on which the target file depends
You can use gcc-M hello. C to test it.
-Mm
It is the same as the one above, but it will ignore the dependency caused by # include <File>.
-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 pass it 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 pass it to the connected program.
-Llibrary
Library Used during compilation
Example usage
Gcc-lcurses hello. c
Compile the program using the ncurses Library
-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.
-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 most optimized level.
High
-G
It is only a compiler. during compilation, information is generated.
-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.
-Static
This option will disable the use of dynamic libraries. Therefore, compiled items are generally large and do not need any
The dynamic connection library can be run.
-Share
This option will try to use the dynamic library, so the generated file is small, but the system needs to use the dynamic library.
-Traditional
Try to make the compiler support the traditional C Language Features
The GNU Debugger is called GDB. This program is an interactive tool that works in character mode. In the X Window System, there is a GDB
The front-end graphics tool is called xxgdb. GDB is a powerful debugging program that can complete the following debugging tasks:
* Set breakpoints;
* The value of the Monitored Program variable;
* One-Step Program Execution;
* Modify the value of a variable.
Before you can use GDB to debug a program, you must use the-G option to compile the source file. You can define the cflags variable in makefile:
Cflags =-G
The following command is often used to run the gdb debugging program:
GDB progname
Enter help at the gdb prompt to list the command categories, including:
* Aliases: Command alias
* Breakpoints: breakpoint definition;
* Data: View data;
* Files: Specify and view files;
* Internals: maintenance command;
* Running: program execution;
* Stack: view the call stack;
* Statu: view the status;
* Tracepoints: trace program execution.
Enter help and the classification name of the command to obtain a detailed list of such commands.
Ref: http://blog.csdn.net/nana08/article/details/6910294