当前位置:网站首页>GCC [6] - 4 stages of compilation
GCC [6] - 4 stages of compilation
2022-07-04 14:16:00 【Small snails in big cities】
List of articles
Preface
GCC Compilation is divided into 4 Stages : Preprocessing 、 compile 、 assembly 、 link
gcc General format of instruction
gcc 【 Options 】 Files to compile 【 Options 】【 The output file 】
| Options | explain |
|---|---|
| -E | control GCC The compiler only preprocesses the source code |
| -S | control GCC The compiler only deals with the compilation phase of the specified file |
| -c | control GCC The compiler only deals with the formulated files to the assembly stage , And generate the corresponding target file |
| -o outfile | Specifies the filename of the output file |
eg: Here is a very simple paragraph hello.c Code , Take this code for example
#include <stdio.h>
#define NAME "mao"
void main()
{
printf("hello:%s\n",NAME);
}
One 、 Pretreatment stage
Preprocessing The main work of this stage is to delete all comments in the program 、 Deal with # The first order . Such as : Expansion of header file 、 Replacement of macro definitions .
For the above code #include <stdio.h> Indicates the import header file , In the pretreatment stage stdio.h The file will be loaded into my hello.c in , And for the... Used in the code NAME, It will be replaced with the real content defined by the macro mao, You can use the following command to perform preprocessing : Generate .i file ,linux The suffix of the file after preprocessing in the system is usually .i
gcc -E hello.c -o hello.i
Two 、 Compile phase
gcc In the compilation stage, various checks will be carried out on the preprocessed code ( Lexical analysis , Syntax analysis , Semantic analysis ), To determine whether our code conforms to the specification , If you generate assembly code (.s Final document )
Be careful :gcc -S You can't only compile pre processed .i file , It means control GCC The compiler only processes the specified file to the compilation stage
- If the file to be compiled is preprocessed
.ifile , beGCCThe compiler only needs to compile this file . - If the file to be compiled is
.cperhaps.cppSource file , beGCCThe compiler preprocesses and compiles it ( Two steps ).
gcc -S hello.i -o hello.s
3、 ... and 、 Assembly stage
hold .s The file is translated into binary .o file ( Target file )
Be careful :gcc -c It's not just about editing .s file , Its meaning is to control GCC The compiler only processes the specified file to the assembly stage
- If the specified file is
.cfile , begcc -cThe instruction will execute on the file Preprocessing 、 compile 、 assembly . - If the specified file is preprocessed
.ifile , begcc -cInstruction to compile and assemble the file . - If the specified file is a compiled file , be
gcc -cInstruction only performs assembly operations on this file .
gcc -c hello.s -o hello.o
Four 、 Link phase
The assembly phase compiles the code into binary files , And other components of the system ( For example, standard library 、 Dynamic link library, etc ) Combined to work properly , For example, call print Function print , In the preprocessing stage, it is only “stdio.h” The declaration in the header file is introduced , There is no function implementation , Then how to call it ?
This is the job of linking , Before linking, we deal with files , And linking is the process of packaging multiple files , It combines all object files and system components into an executable .
gcc hello.o -o hello
边栏推荐
- 富文本编辑:wangEditor使用教程
- 吃透Chisel语言.09.Chisel项目构建、运行和测试(一)——用sbt构建Chisel项目并运行
- sharding key type not supported
- Xcode 异常图片导致ipa包增大问题
- ARouter的使用
- Gorm data insertion (transfer)
- 自主工业软件的创新与发展
- Unity Shader学习(三)试着绘制一个圆
- What is the real meaning and purpose of doing things, and what do you really want
- DDD application and practice of domestic hotel transactions -- Code
猜你喜欢

Why should Base64 encoding be used for image transmission

DDD application and practice of domestic hotel transactions -- Code

瑞吉外卖笔记

205. 同构字符串

【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结

Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?

Vscode common plug-ins summary

Ruichengxin micro sprint technology innovation board: annual revenue of 367million, proposed to raise 1.3 billion, Datang Telecom is a shareholder

Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million

The font of markdown grammar is marked in red
随机推荐
Gorm 读写分离(转)
Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
LifeCycle
Gorm data insertion (transfer)
Assertion of unittest framework
吃透Chisel语言.03.写给Verilog转Chisel的开发者(没有Verilog基础也可以看看)
R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
[FAQ] Huawei Account Service Error Report 907135701 Common reasons Summary and Solutions
R语言使用dplyr包的mutate函数对指定数据列进行标准化处理(使用mean函数和sd函数)并基于分组变量计算标准化后的目标变量的分组均值
markdown 语法之字体标红
锐成芯微冲刺科创板:年营收3.67亿拟募资13亿 大唐电信是股东
为什么图片传输要使用base64编码
FS4059C是5V输入升压充电12.6V1.2A给三节锂电池充电芯片 输入小电流不会拉死,温度60°建议1000-1100MA
IP 实验室月复盘 · 第 5 期
去除重复字母[贪心+单调栈(用数组+len来维持单调序列)]
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布
Error in find command: paths must precede expression (turn)
Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended