当前位置:网站首页>[basic] the difference between dynamic link library and static link library
[basic] the difference between dynamic link library and static link library
2022-07-26 15:08:00 【Call me little Paris in the East】
One 、 Introduction to static link library and dynamic link library
C or C++ The program needs to go through... From source file to executable file 4 Stages
They are pretreatment 、 compile 、 Compilations and links .
The work to be completed in the link stage , It is to integrate the object file generated by each source file in the same project and the library file used in the program into an executable file .Although library files are explicitly used for link , But the compiler provides 2 A way to link , They are called static links and dynamic links respectively .
Use the static link method to realize the link operation , The library file of is called static link library ;
Use dynamic link to realize link operation , The library file of is called dynamic link library .stay Linux In the distribution system , The suffix of the static link library file is general Commonly used .a Express , The suffix of dynamic link library is general Commonly used .so Express ;
stay Windows In the system , The suffix of the static link library file by .lib, The suffix of dynamic link library by .dll.GCC When the compiler generates an executable , By default, the dynamic link library will be used first to realize the link operation , Unless there is no dynamic link library required by program files in the current system environment ,GCC The compiler will select the corresponding static link library . If there are neither ( perhaps GCC Compiler not found ), Then the link fails .
stay Linux Distribution in , Static link libraries and dynamic link libraries are usually stored in /usr/bin perhaps /bin Under the table of contents

Two 、 difference
1、 Static link library
- The way of static link library to realize link operation is very simple , That is, where is used in the program file Function modules in library files ,GCC The compiler will translate the template code , Directly copy to the appropriate location of the program file , Final generation of executable .
- Static library in Link phase , Will Assemble the generated object file .o Link and package to executable file together with the referenced Library .
advantage :
Strong portability , Can operate independently , That is, the generated executable file can run independently without the support of any static library file .
Executable programs are no longer related to library functions , It can be implemented in any environment .
Inferiority :
Code redundancy 、 The size of the executable file is large : If the same function module in the library is called multiple times in the program file , Then the module code will be copied many times , The generated executable file will contain multiple identical pieces of code , Make code redundant . Compared with the executable generated by dynamic link library , The executable file generated by the static link library is larger .
And if the static library used is updated and changed , Your program must be recompiled .
2、 Dynamic link library
Dynamic link library , Also known as shared link library . When using dynamic link library to realize link operation , Where does the function module of the library file need in the program file ,GCC compiler The code of this function module will not be directly copied to the file , Instead, the location information of the functional module is recorded in the file , Directly generate executable file .
obviously , The executable generated in this way cannot run independently . The executable file generated by dynamic link library runs ,GCC The compiler will load the corresponding dynamic link library into memory , Because the location information of the required functional modules is recorded in the executable file in advance , So with the support of the existing dynamic link library , It can also run successfully .
If the static library liba.lib Updated , So applications that use it all need to be recompiled , It could be a small change , It causes the whole program to download again , Full update .
Dynamic libraries are not connected to the target code when the program is compiled , It's loaded when the program is running .
Different applications call the same library , Only one instance of the shared library is needed in memory , Avoid the problem of space waste . Dynamic library is loaded when the program is running , It also solves the update of static library to program 、 Trouble deploying and publishing pages . Users only need to update the dynamic library , Incremental updating .
advantage :
Generated The execution file is small , Because the executable file records the address of the function module , The real implementation code will be loaded into memory when the program is running , Even if the function module is called many times , Using the same implementation code ( This is why dynamic link libraries are called shared link libraries ).
Dynamic library changes do not affect your program , Therefore, it is more convenient to upgrade the dynamic function library .
Inferiority :
Poor portability , Can't run independently , You must use the corresponding library files .
https://blog.csdn.net/oqqHuTu12345678/article/details/125083174
https://www.bilibili.com/read/cv15423597/
https://blog.csdn.net/breakpoints_/article/details/116166379
边栏推荐
- Database expansion can also be so smooth, MySQL 100 billion level data production environment expansion practice
- 【LeetCode每日一题】——121.买卖股票的最佳时机
- php反序列化部分学习
- 带你熟悉云网络的“电话簿”:DNS
- Minecraft 1.16.5 module development (52) modify the original biological trophy (lot table)
- 数据权限就该这么设计,yyyds!
- jmeter分布式
- postman 环境变量设置代码存放
- About the selection of industrial control gateway IOT serial port to WiFi module and serial port to network port module
- 谷歌尝试为ChromeOS引入密码强度指示器以提升线上安全性
猜你喜欢

【LeetCode每日一题】——268.丢失的数字

Next generation visual transformer: Unlocking the correct combination of CNN and transformer

Chapter 08_ Principles of index creation and design

楚环科技深交所上市:市值27亿 民生证券是股东

Parallel d-Pipeline: A Cuckoo Hashing Implementation for Increased Throughput论文总结

Pokemon card evolution jsjs special effect

数商云:引领化工业态数字升级,看摩贝如何快速打通全场景互融互通

谷歌尝试为ChromeOS引入密码强度指示器以提升线上安全性

外文文献查找技巧方法有哪些

数据权限就该这么设计,yyyds!
随机推荐
Partial learning of PHP deserialization
【华为联机对战服务】客户端退出重连或中途进入游戏,新玩家如何补帧?
谷歌尝试为ChromeOS引入密码强度指示器以提升线上安全性
R语言检验相关性系数的显著性:使用cor.test函数计算相关性系数的值和置信区间及其统计显著性(如果变量来自正态分布总体使用皮尔森方法pearson)
Crystal special decoration submitted for registration: the first quarter revenue fell by 80%, and Chen Bo controlled 68.5% of the equity
9、学习MySQL DELETE 语句
笔记(5)
median filter
Difference between filter and interceptor
driver开发环境
CVE-2022-33891漏洞复现
JS analog clock with text label
AMB | towards sustainable agriculture: rhizosphere microbial engineering
Simulation of character function and string function
楚环科技深交所上市:市值27亿 民生证券是股东
Introduction to C language must brush the daily question of the collection of 100 questions (1-20)
DevSecOps,让速度和安全兼顾
什么是传输层协议TCP/UDP???
精益产品开发:原则、方法与实施
JS to realize the number to amount price thousand separator