1. Preprocessing
At this time, the compiler will scan the C source files one by one. h file, the entire. the H file is included in. c file to form a new. c file (the actual implementation process may not be like this, but the principle is like this ). At the same time, interpret related pre-processing commands, such as replacing macros with actual values.
2. Compile the source file
At this time, the compiler will scan the source file generated after step 1Source codeCompile the code into a machine code to generate the target file. If you find that a type is not a self-contained type of the compiler, such as some custom struct, you will find this type in the source file.Can I find the declaration of this type?If not, an error is returned.All functions generate only one symbol during compilation and do not check whether the actual body exists.However, if you find thatCodeIf the declaration of this function is not found before the row, the compiler will give a warning: implicit function call.
3. link all target files
In this case, the compiler collects all the symbols in the target file, such as function symbols, andSearch for EntityIf no address is found, an error is returned. If no error is found, a real address is assigned to these symbols. After an address is assigned, the actual address is replaced with the symbol in each target file, merge all target files into an executable file.