当前位置:网站首页>Compilation and link of C language program
Compilation and link of C language program
2022-07-19 02:00:00 【Monastic -0323】
Preface :
Once the “hello word” Shocking world , Let countless apes flock . Now let me talk about my understanding of this note .
The process of the birth of notes
I take c/c++ give an example , Use the compiler as the panel , The linker is the string , Create a zither . Last use c The code waves the strings for everyone , Feel the birth of this wonderful note .
Detailed explanation of zither panel - compiler
The functional core of the compiler :“c The language code -->( precompile )–> Assembly code -->( Compile optimization )–> Machine code ”
1. precompile
Preprocessing instructions contain macro definitions , Conditional compilation , The header file contains , Special symbols, etc ; The compiler will first process the preprocessing instructions , abbreviation precompile , precompiled The output file in , Constant only ; Like numbers 、 character string 、 Definition of variables , as well as C Keywords of language , Such as main, if , else , for , while , { , } , + , - , * , \ wait .
Preprocessing :
#pragma #error#pragmaInstructions can be followed by parameters , And according to the parameter content , Number, etc , Its functions vary greatly . The most commonly used instruction is #pragma once, Used to prevent repeated references to header files .Macro definition :
#define 【SrcName】 【DesName】
Direct will DesName Replace with SrcName, For subsequent use of macros, use SrcName.Conditional compilation :
#if #else #elif #endif #ifdef #ifndef
Conditional compilation allows programmers to selectively compile code segments . therefore , The compiler will filter useless code segments according to conditional compilation statements , Do not participate in the compilation process ( Even if the error is not reported ).The header file contains :
*#include <> #include ""*
Use#includeThe main purpose of is to make different source programs use common variables , Avoid repeating definitions .<>It mainly includes “/ usr/ include” System files under the path .“”It mainly includes programmer's customized header files , The storage path is generally at the same level as the system path .Special symbols
line FILE
#line Will be replaced with line number ,FILE Replaced file name, etc ;
2. compile , Optimize
The precompiled output file is used as compilation , Optimization of the Input file . Through grammar , lexing , take c Code conversion to equivalent assembly code ;
compile
According to the preprocessed output file , Will conform to the grammar , Lexical statements are translated into equivalent assembly language ;Optimize
Compiler optimization is the most complex compilation stage , In terms of details , It will delete invalid code , Delete public expression , Reduce cycle strength and other ways to optimize code ; In general , Optimization can be divided into assembly code optimization and machine code optimization , The former is related to computers , The latter is closely related to the hardware structure .
3. assembly
Assembly process actually refers to the process of translating assembly language code into target machine instructions . The generated relocatable file consists of data segment and code segment . It can create an executable or shared object file through links .
Detailed explanation of zither strings - The linker
The linker associates machine language code with related files ( Symbol table parsing , relocation ), The process of generating executable files ; For example, a function or variable in a header file is called in a function , Just link that header file and its specific implementation file .
1. Static links
The linker : Copy the code in the object file to the final executable ;
Static link library : A collection of object codes ;
Static link is to copy the relevant code to the corresponding location of the source code , Participate in program generation .
2. Dynamic links
In the process of program generation , Only a few symbols required for normal compilation are provided . During program execution , Mapping all contents in the dynamic link library to the address space of the corresponding process , Ensure the normal execution and calling of the program .
Zither playing - Note birth
The four processes of note birth are summarized as follows : Precompiling (.c) —> compile 、 The optimizer (.s、.asm)—> Sink programming (.obj、.o、.a、.ko) —> Link program (.exe、.elf、.axf etc. ). Understanding of the compilation process , I'm still at the threshold , Need to learn more . Welcome to consult each other , Common progress
about GCC compiler , The compilation instructions corresponding to the above process are as follows :
| name | GCC Instructions | result |
|---|---|---|
| c Language | nothing | *.c |
| precompile | -E | *.i |
| compile | -S | *.s |
| assembly | -C | *.o |
| link | -ld | *.exe |
边栏推荐
猜你喜欢

Hands on deep learning - deep learning computing
![[literature reading] small footprint keyword spotting with multi scale temporary revolution](/img/18/ffa23bee826d78c388fde2f5d49282.png)
[literature reading] small footprint keyword spotting with multi scale temporary revolution

【文献阅读】VAQF: Fully Automatic Software-Hardware Co-Design Framework for Low-Bit Vision Transformer

5章 性能平台GodEye源码分析-第三方模块

二阶边缘检测 - Laplacian of Guassian 高斯拉普拉斯算子

Owl Eyes: Spotting UI Display Issues via Visual Understanding

02基于ZigBee的智能家居系统设计

性能强悍的图表组件库 ScottPlot
Mxnet network model (IV) Gan neural network

openGauss Developer Day 2022|东方通诚邀您莅临“东方通生态工具分论坛”
随机推荐
[literature reading] multi state MRAM cells for hardware neural computing
0章 性能平台GodEye源码分析-课程介绍
Combined key screenshot analysis
动手学深度学习---深度学习计算篇
AURIX Development Studio安装
监听浏览器返回操作-禁止返回上一页
欢迎进入Hensen_的博客目录(全站式导航)
Cocos Creator 3.0 基础——常见操作
Fairness in Semi-supervised Learning: Unlabeled Data Help to Reduce Discrimination
Hands on deep learning -- from full connection layer to convolution layer
typeorm mysql upsert操作
A causal linear model to quantify edge unfairness for unfair edge prioritization
C language operator priority
[literature reading] vaqf: full automatic software hardware co design framework for low bit vision transformer
Xcode11添加引导页(升级后Launch Images Source选项不见了)
[go language] detailed explanation of dynamic library and static library
Allegro Design Entry CIS 和 Orcad Capture CIS 关系
Fisher线性判别分析Fisher Linear Distrimination
MXNet网络模型(四)GAN神经网络
Fair Attribute Classification through Latent Space De-biasing