当前位置:网站首页>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
边栏推荐
- Learn how to compile basic components of rainbow from the source code
- Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
- Analysis of maker education in innovative education system
- GFS distributed file system
- How to understand distributed architecture and micro service architecture
- A method for quickly viewing pod logs under frequent tests (grep awk xargs kuberctl)
- Exercise arrangement 2.10, 11
- MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)
- 单元测试报告成功率低
- rsync远程同步
猜你喜欢
Obsidan之数学公式的输入
[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)
[hard core science popularization] working principle of dynamic loop monitoring system
Ebpf cilium practice (1) - team based network isolation
Analysis of maker education in innovative education system
Golang 编译约束/条件编译 ( // +build <tags> )
Exercise arrangement 2.10, 11
The truth of robot education in hands-on practice
Famine cloud service management script
The field value in Splunk subquery fuzzy matching CSV is*
随机推荐
接口作为参数(接口回调)
The field value in Splunk subquery fuzzy matching CSV is*
[machine learning] watermelon book data set_ data sharing
[Yu Yue education] C language programming reference of Zhongbei College of Nanjing Normal University
opencv学习笔记二——图像基本操作
Through the "last mile" of legal services for the masses, fangzheng Puhua labor and personnel law self-service consulting service platform has been frequently "praised"
National SMS center number inquiry
Famine cloud service management script
One click installation of highly available Nacos clusters in rainbow
Open3D ISS关键点
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
Opencv learning notes II - basic image operations
Use of any superclass and generic extension function in kotlin
打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
Transformation function map and flatmap in kotlin
Domain specific language / DSL in kotlin
Rsync remote synchronization
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
Laravel8 uses passport login and JWT (generate token)
详解华为应用市场2022年逐步减少32位包体上架应用和策略