当前位置:网站首页>Compilation and linking of programs
Compilation and linking of programs
2022-07-07 08:35:00 【WFForstar】
List of articles
One . preface
For normal application development , We need to pay little attention to the compilation and linking process , Because the usual development environment is a popular integrated development environment (IDE), such as Visual Studio、Delphi etc. . In this way IDE Generally, the process of compiling and linking is completed in one step , Usually, the The process of compiling and linking together is called building (Build ).
Command line to compile a source code file , A simple sentence **“gcc hello.c”**( The default output will be a.out This executable file ) The command involves a very complex process .
Two . The hidden process
1 . Linux The process of going on
#include<iostream>
int main()
{
std::cout << "Hello world" << std::endl;
return 0;
}
hello world This code is too classic , stay Linux Only the following steps are needed in 
It's compiled .(a.out Is the name of the default executable )
As a matter of fact , The above process can be divided into four steps , Respectively :
Preprocessing , compile , assembly , link
2 . precompile
Precompiling mainly deals with those in the source code with “#” Precompiled instructions at the beginning , Such as “#include”#define" wait
Just use the command line as shown in the figure 
Then you will find one more in the directory hello.i file , After opening, you will find .i There is no macro definition in the file
3 . compile
During the compilation process, the preprocessed files will be subjected to a series of lexical analysis , Grammatical analysis and , After semantic analysis and optimization, corresponding Assembly code file .
Just use the command line as shown in the figure 
4 . assembly
The assembler converts assembly code into instructions that the machine can execute , Almost every assembly statement corresponds to a machine instruction , So the assembly process is very simple , There is no need to optimize .
Just use the command line as shown in the figure 
5 . link ( Here, take static links as an example )
The time of static link is before the executable file is generated , So we need to use the command line to link duck .
In our actual development , It's not possible to put all the code in one source file , So there will be multiple source files , And multiple source files are not independent , And there will be multiple dependencies , If one source file may call a function defined in another source file , But each source file is compiled independently , each *.c The document will form a *.o file , In order to satisfy the dependency mentioned above , You need to link the target files generated by these source files , To form an executable program , The process of linking is static linking .
Just use the command line as shown in the figure 
边栏推荐
- 21 general principles of wiring in circuit board design_ Provided by Chengdu circuit board design
- Opencv learning note 5 - gradient calculation / edge detection
- Download and install orcale database11.2.0.4
- The use of generics and vararg variable parameters in kotlin
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- [hard core science popularization] working principle of dynamic loop monitoring system
- BiSeNet的特點
- [quick start of Digital IC Verification] 10. Verilog RTL design must know FIFO
- Using helm to install rainbow in various kubernetes
- Function extension, attribute extension and non empty type extension in kotlin
猜你喜欢

2-3 lookup tree

One click installation of highly available Nacos clusters in rainbow

The truth of robot education in hands-on practice

All about PDF crack, a complete solution to meet all your PDF needs

Interpreting the practical application of maker thinking and mathematics curriculum

Wang Zijian: is the NFT of Tencent magic core worth buying?
![[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?](/img/ff/81a7b2ec08a6a422a5cf578c1fed13.jpg)
[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?

Rainbow combines neuvector to practice container safety management

Splunk中single value视图使用将数值替换为文字

SSM integration
随机推荐
ES6_ Arrow function
National SMS center number inquiry
Golan idea IntelliJ cannot input Chinese characters
2-3 lookup tree
Opencv learning notes 1 -- several methods of reading images
All about PDF crack, a complete solution to meet all your PDF needs
Input and output of floating point data (C language)
Go write a program that runs within a certain period of time
Several ways of lambda used in functions in kotlin (higher-order functions)
[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?
Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications
String operation
Go语言中,函数是一种类型
You should use Google related products with caution
Exercise arrangement 2.10, 11
Merge sort and non comparison sort
Transformation function map and flatmap in kotlin
接口作为参数(接口回调)
Golang 编译约束/条件编译 ( // +build <tags> )
Lua programming learning notes