Getting started with Linux_11_gcc (I)
Thank you for your reference. If you have any errors or questions, please leave a message to correct them. Thank you.
I. What is gcc 1? The Author of the gcc (GNUC Compiler) Compiler is Richard Stallman, and he is also the founder of the GNU project. 2. What is gcc? gcc is the abbreviation of GNUCompiler Collection. Originally as a C language Compiler (GNUC Compiler), it now supports multiple languages, such as C, C ++, Java, Pascal, Ada, and COBOL. 3. gcc supports multiple hardware platforms and even provides comprehensive support for uncommon computers such as MMIX designed by DonKnuth.
Ii. gcc features 1. gcc is a portable compiler that supports multiple hardware platforms. 2. gcc is not only a local compiler, but also cross-platform cross-compilation. 3. gcc has multiple front-ends for parsing different languages. 4. gcc is modular and can be added to support the new language and new CPU architecture. 5. gcc is a free software.
Iii. gcc compilation process 1. Pre-Processing 2. Compile: Generate assembler 3. Compile ): generate a binary target program from the assembler. 4. Link (Linking)
5. gcc program compilation process
Hello Program is an advanced C Language Program, which is easy to understand. To run the hello. c program on the system, each C statement must be converted to a low-level machine command. These commands are then packaged into an executable target file and stored in binary format on the disk.
Iv. Common gcc options
Option name |
Function |
-O |
Generation target (. I,. s,. o, executable files, etc) |
-C |
Notify gcc to cancel the link, that is, compile the source code and generate the target file at the end. |
-E |
Only run the C pre-Compiler |
-S |
Tells the compiler to stop compilation after an assembly language file is generated. The generated assembly language file extension is. s. |
-Wall |
Issue a warning to gcc when there is a problem with the source file code |
-Idir |
Add the dir directory to the directory path of the search header file |
-Ldir |
Add the dir directory to the directory path of the search database |
-Llib |
Link lib Library |
-G |
Embedded debugging information in the target file for debugging programs such as gdb |
1. gcc example (1), gcc-E hello. c-o hello. I (preprocessing) (2), gcc-S hello. i-o hello. s (Compilation) (3), gcc-c hello. s-o hello. o (assembly, generate relocated target file) (4), gcc hello. o-o hello (link to generate executable target file) (5), gcc hello. c-o hello (directly compile and link to the executable target file) (6), gcc-c hello. c or gcc-c hello. c-o hello. o (compile and generate relocated target files)
2.-Wall usage (1) this option is recommended for beginners. In the following example, if the-Wall compiler is not added, no error is reported, but the result is not as expected.
# Include
Int main (void)
{
Printf ("Twoplus two is % f", 4 );
Return 0;
}
5. Multi-file compilation with gcc
1. Three files exist: hello_fn.h hello_fn.c main. c
2. One-time compilation (1) gcc hello_fn.cmain.c-o newhello
3. Independent compilation (1) gcc-Wall-c main. c-o main. o (2) gcc-Wall-c hello_fn.c-o hello_fn.o (3) gcc-Wall main. o hello_fn.o-o newhello
4. The benefit of independent compilation is that if the main. c program is modified and compiled independently, hello_fn.c does not need to be compiled because hello_fn.c is not modified. You only need to compile main. c: gcc-Wall-c main. c-o main. o. If one-time compilation is used, hello_fn.c and main. c will be compiled every time, which is equivalent to one more hello_fn.c compilation. For large programs, using independent compilation can greatly reduce the Compilation Time.