A brief discussion on C language program compilation and linking

A brief discussion on C language program compilation and linking

1. Necessity

Why do we need to compile and link programs written in C language? In other words, why do we need to compile and link programs written in high-level languages?
With the development of the computer industry, modern computers can actually only recognize machine language. Machine language is a language directly abbreviated by computer instruction code, expressed in binary, and is the only language that a computer can directly recognize and execute.
The program we wrote is as follows:

#include <stdio.h>
int main()
{
    
    
	printf("hello world!");
	return 0;
}

All statements are written in text.
It's as if we are speaking in dialect, and conversations in formal situations need to switch to Mandarin mode. Computer compilation and linking have the effect of conversion. Transforming our dialect (become language) into Mandarin (machine language). Let the computer recognize it and then run our program normally.

2. Process

Bit Employment Course Courseware Explains Compilation, Linking and ProcessFigure 1 above illustrates the compilation and linking process under the GCC compiler.
Next 2 explains the general content of each process.
Preprocessing stage : The preprocessor (cpp) modifies the original C program according to commands starting with the character #.
Compilation phase : The compiler (eel) translates text file xxx.i into text file xxx.s, which contains an assembly language program.
Assembly stage : Next, the assembler (as) translates xxx.s into machine language instructions, packages these instructions into a format called relocatable object program obj (relocatable object program), and saves the result in the object file xxx .o in.
Link stage : The linker (ld) is responsible for processing the xxx.a file formed by calling the internal library function, and linking it with the file xxx.o in the assembly stage, and finally forming an executable file.


  1. Bit Employment Courseware; ↩︎

  2. In-depth understanding of computer systems; ↩︎

Guess you like

Origin blog.csdn.net/BlankXiangzw/article/details/133363149