当前位置:网站首页>C language program environment, compilation + link
C language program environment, compilation + link
2022-04-21 16:34:00 【Unknown little Lai】
List of articles
- One 、 The translation environment of the program ( Compile and link )
- Two 、 The running environment of the program
One 、 The translation environment of the program ( Compile and link )
stay ANSI C In any implementation of , There are two different environments :
- The first is the translation environment , In this environment, the source code is converted into executable machine instructions .
- The second is the execution environment , It's used to actually execute code .
Here's the picture : This is the general process of our compiler compiling a source file into an executable file

- Each source file that makes up a program (test.c) Through the compilation process, they are converted into object code (test.obj)
- Each target file is linked by a linker (linker) Tied together , Form a single and complete executable program .
- The linker will also introduce standards c Any function in the function library used by the program .
For a source file (test.c) Become the final binary file (test.exe) It can be simply represented by the following figure :


Looking at the picture, we know : The compilation is divided into three steps :
- precompile ( Preprocessing )(test.c —>test.i)
(1) Deal with all the comments , Replace... With a space
(2) Will all #define Delete , And expand all macro definitions
(3) Processing conditional compilation instructions #if、#ifdef、#elif、#else、#endif
(4) Handle #include, Expand the included files
(5) Keep what the compiler needs to use #pragma Instructions - compile (test.i —>test.s)
(1) hold C Compile language code into assembly code
(2) Grammatical analysis , Lexical analysis , Semantic analysis , Symbols are summarized to form a symbol table - assembly (test.s —>test.o)
Assembly process actually refers to the process of translating assembly language code into target machine instructions . For each... Processed by the translation system C Language source , Will eventually get the corresponding target file through this processing . What is stored in the object file is the machine language code of the object equivalent to the source program .
After compiling, execute the link , What will links do ?
- Merge segment tables
- Symbol table merging and symbol table relocation
- In the end (test.exe)
Two 、 The running environment of the program
- The program must be loaded into memory , In an operating system environment : Usually this is done by the operating system . In an independent environment , The loading of the program must be arranged manually , It can also be done by putting executable code into read-only memory .
- The execution of the procedure begins , Then call main function .
- Start executing program code , At this point, the program will use a runtime stack , Store function local variables and return address , The program also uses static (static) Memory , Variables stored in static memory retain their values throughout the execution of the program .
- To terminate the program . Normal termination main function , It may also be an accidental termination ( Code error )
版权声明
本文为[Unknown little Lai]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211544138997.html
边栏推荐
- C# 滑动验证码|拼图验证|SlideCaptcha
- 外包学生管理系统详细架构设计文档
- 手把手教你基于LXD用OAK-D和ROS noetic做ORB SLAM3
- What kind of earphone doesn't hurt your ears? Bone conduction earphone for non ear wearing
- 4.25解锁OpenHarmony技术日!年度盛会,即将揭幕!
- OJ每日一练——等级成绩
- ES6 how to determine whether an array is repeated
- 手机硬件都有哪些
- OJ每日一练——最大公约数与最小公倍数
- IOS development interview strategy (KVO, KVC, multithreading, lock, runloop, timer)
猜你喜欢

SQL -- database operation (DDL, DML, DQL) + use the command to view the storage location of the current database (database version query)

Transformer model technology long article

Want to make a fortune by "leaking data"? What a punishment

CLion 中添加 release 配置

elmentUI表单中input 和select长度不一致问题

C sliding verification code | puzzle verification | slidecaptcha

Invalid bound statement (not found)

Apache安全配置

排序课后练习题

php如何把负数转为正整数
随机推荐
OJ daily practice - maximum common divisor and minimum common multiple
手机硬件性能的发展主要受哪几方面制约
苹果A13处理器在技术上有哪些创新?
Xiaomi civi 1s is priced from 2299 yuan. It focuses on beauty and gives you freedom to appear on the camera
Haotian Xuhui signed a contract with Changyang technology to jointly build a new ecosystem of industrial Internet security
Which exchange is rapeseed meal futures listed on? How is it safest for a novice to open a futures account?
Is 5g SOC chip technology mature at present?
What are the advantages of mini led
Buuctf's [actf2020 freshman competition] BackupFile
求字符串最长子串
程序设计天梯赛L3-29 还原文件(dfs就过了,离离原上谱)
云呐:机房资产管理系统web版,设备资产信息管理的应用
Jianmu continuous integration platform v2 3.0 release
Project training 2022-4-21 (flame grass)
Case of kingbasees v8r3 cluster deleting data nodes online in Jincang database
What are the similarities and differences between LCD and OLED screens
Detailed explanation of websocket protocol
OJ daily practice - number of characters
菜粕期货是那个交易所上市的?新手怎么期货开户最安全?
Dating and asynchronous functions