当前位置:网站首页>About Library (function library), dynamic library and static library
About Library (function library), dynamic library and static library
2022-06-30 10:34:00 【Fat Xiao Deng】
Make dynamic library , Static library , I have some understanding , At the same time, it is also convenient for me to check my notes in the future , If there is a mistake , Please comment , thank you !
library ( function library ):
Function library is a collection of functions with certain functions established by the system . The library stores the name of the function and the corresponding object code , And relocation information required during connection . Users can also create their own user function library according to their own needs . ( Convenient to call , And encrypt the code )
Be careful : Function functions are stored in the library , Don't put main Functions are encapsulated .
Dynamic library (libname.so):
characteristic :
(1) When compiling an executable using functions in the library , It does not compile the code in the library . Programs compiled with dynamic libraries are relatively small .
(2) Executable compiled by dynamic library , This dynamic library is required in the system environment variable during execution , Otherwise, it cannot run .
Make :gcc -shared -fPIC -o lib Library name .so .c .c …
.c .c …: All function functions .c file
shared: To generate .so Dynamic library files
-fPIC: -fPIC Works in the compilation phase , Tell the compiler to generate location independent code (Position-Independent Code), In the generated code , No absolute address , All use relative addresses , Therefore, the code can be loaded anywhere in memory by the loader , Can be executed correctly . This is what shared libraries require , When the shared library is loaded , The location in memory is not fixed .
Each library has one or more corresponding header files
(1) compile
gcc .c -o Executable file name -I( Big i) Follow file path -L Follow the library file path -l( A lowercase letter l) Library name
.c : The main function .c file
Executable file name : Suggested main function name _so, It is convenient to know which file is generated in the future
-I( Big i) Follow file path : Link header file
-l( A lowercase letter l) Library name : -l There is no space between the database name and the previous one
Library name : Do not prefix lib, And no suffix .so
This dynamic library is available in the system environment variable Copy the dynamic library to /lib or /usr/lib in
(2) perform
./ Executable file name
Static library (libmame.a):
characteristic :
(1) When compiling an executable using functions in the library , Will replace Code is compiled into . Programs compiled with static libraries are relatively large .
(2) Executable compiled by static library , This library is not required in the system environment variable during execution , It can also run .
Make :gcc .c -o .o -c
①.c: every last .c, Can only be generated one by one .o file
②ar cr lib Library name .a .o .o … -c
ar : Packaging tools Can be used to create , Modify library file , Extract from the library file Of .o modular
c : One option , Represents creating a library , Create a library file whether it exists or not .
r : One option , It means that you will .o Insert the module into the library .
.o .o …: All function functions .c File generated .o Redirectable files
(1) compile
gcc .c -o Executable file name -I( Big i) Follow file path -L Follow the library file path -l( A lowercase letter l) Library name -static( See the following precautions )
Executable file name : Suggested main function name _a, It is convenient to know which file is generated in the future
-I( Big i) Follow file path : Link header file
-l( A lowercase letter l) Library name : -l There is no space between the database name and the previous one
Library name : Do not prefix lib, And no suffix .a
Be careful : There are dynamic libraries and static libraries under the current path , The dynamic library will be compiled by default first , In order to compile with a static library, you need to add -static
(2) perform
./ Executable file name
边栏推荐
- 技能梳理[email protected]基于51系列单片机的智能仪器教具
- Gd32 RT thread RTC driver function
- MySQL index, transaction and storage engine of database (2)
- “昆明城市咖啡地图”再度开启,咖啡拉近城市距离
- MIT-6874-Deep Learning in the Life Sciences Week4
- 记一次实习的经历,趟坑必备(一)
- Ant s19xp appeared in 140t, why is it called the computing power ceiling by the world
- Skill combing [email protected] voice module +stm32+nfc
- Open source! Wenxin large model Ernie tiny lightweight technology, accurate and fast, full effect
- Deployment of efficient and versatile clusters lvs+kept highly available clusters
猜你喜欢

马斯克推特粉丝过亿了,但他在线失联已一周

Basic MySQL operation commands of database

Koreano essential creates a professional style

GNN hands on practice (II): reproduction graph attention network gat

华南产业集团发力数字经济,城链科技发布会成功召开
[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled"/>技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled

Migrate full RT thread to gd32f4xx (detailed)

Dow Jones Industrial Average
![[AGC] build service 3- authentication service example](/img/32/44547c00476a055557dd1790e18849.png)
[AGC] build service 3- authentication service example

Remember the experience of an internship. It is necessary to go to the pit (I)
随机推荐
CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection
Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home
GeoffreyHinton:我的五十年深度学习生涯与研究心法
Tooltips in the era of touch
逸仙電商發布一季報:堅持研發及品牌投入,實現可持續高質量發展
技能梳理[email protected]+adxl345+电机震动+串口输出
MySQL index, transaction and storage engine of database (3)
Es common curl finishing
The rising star of Goldshell STC box
Leetcode question brushing (II) -- sorting (go Implementation)
mysql数据库基础:TCL事务控制语言
Skill sorting [email protected]+adxl345+ Motor vibration + serial port output
Gd32 RT thread PWM drive function
郭琳加冕 2022第三季完美大师 全球人气季军
KOREANO ESSENTIAL打造气质职场范
移植完整版RT-Thread到GD32F4XX(详细)
MySQL advanced SQL statement of database (2)
"Hackers and painters" -- why not be stupid
"Kunming City coffee map" was opened again, and coffee brought the city closer
潘多拉 IOT 开发板学习(HAL 库)—— 实验1 跑马灯(RGB)实验(学习笔记)