C language compilation generally has three steps:
- Pre-compilation:
GCC-E-O A.E a.c
Precompiled A.C file with the resulting target file named A.E
Precompilation is to replace the contents of the header file contained in the include with the C file, while deleting the unused comments in the code
Example:
Main.c
#include <stdio.h>
#include "sum.h"
int main () {
int m = 6;
int n = 5;
int result = SUM (m,n); printf ("hello\n%\n", result);
Sum.h
int sum (int x,int y);
After running the result is:
The first step is this!
2. compiling
Gcc-s-O a.s a.e
Translate the A.E into an ASCII assembly-language file A.S.
3. Links
Gcc-o a A.S
This line of command tells GCC to link the source program A.O to generate an executable program a
GCC does not have any parameters, indicating that it is a link
The basic options for the GCC compiler are the following table:
Type |
Description |
-E |
Stop after preprocessing, do not compile, assemble, and connect |
-S |
Stop after compiling, do not assemble and connect |
-C |
Compile or assemble the source file without connecting |
-O File |
Specifies the output file |
C-language include header file
- Include is to tell the compiler that it contains a header file
- In the C language, any library function call needs to contain a header file
- Header files are also equivalent to a document declaration
- If you put the main function in the first file and put the custom function in the second file, you need to declare the function prototype in the first file.
- If a function prototype is included in a header file, then it is not necessary to declare its prototype every time the function is used, it is a good habit to put the function declaration into the header file!
- Header files may not need to be compiled
- You can view the specific statement
- The header file plus the O file of the implementation file is submitted to the user, no need to know the source code
- o files are precompiled, so the compilation time is greatly improved when the whole project is compiled.
- When a file (A.C file) is dependent on the header file (b.h), A.O files do not need to be recompiled if the B.O files formed after B.C compilation are recompiled
- Can greatly reduce the chance of errors in manual copying and pasting
Considerations for header files:
- < header file, indicating that the C language compiler looks for related header files under the system directory (that is, the include directory of the GCC compiler)
- "Header file" for the C language compiler to look for related header files in the user's current directory
- If it is a required header file that uses the C library function, it must be #include<>
- If the user-defined header file is used, it must be # include ""
C language compilation process and GCC compilation parameters