当前位置:网站首页>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
边栏推荐
- 逸仙電商發布一季報:堅持研發及品牌投入,實現可持續高質量發展
- What is the real performance of CK5, the king machine of CKB?
- Ant s19xp appeared in 140t, why is it called the computing power ceiling by the world
- Leetcode question brushing (II) -- sorting (go Implementation)
- Migrate full RT thread to gd32f4xx (detailed)
- Implementation of monitor program with assembly language
- “昆明城市咖啡地圖”活動再度開啟
- KOREANO ESSENTIAL打造气质职场范
- MIT-6874-Deep Learning in the Life Sciences Week6
- ArcGIS Pro脚本工具(6)——修复CAD图层数据源
猜你喜欢

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

Dyson design award, changing the world with sustainable design

Dow Jones Industrial Average

KOREANO ESSENTIAL打造气质职场范

郭琳加冕 2022第三季完美大师 全球人气季军
[email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled"/>Skill sorting [email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled
[email protected]在oled上控制一条狗的奔跑"/>技能梳理[email protected]在oled上控制一条狗的奔跑

ArcGIS PRO + PS vectorized land use planning map

MySQL index, transaction and storage engine of database (2)

South China Industrial Group launched digital economy and successfully held the city chain technology conference
随机推荐
June training (day 30) - topology sorting
mysql数据库基础:约束、标识列
【Rust日报】2021-01-23 几个新库发布
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
RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装
Notes on numerical calculation - iterative solution of linear equations
Launch of Rural Revitalization public welfare fund and release of public welfare bank for intangible cultural heritage protection of ancient tea tree
Leetcode question brushing (III) -- binary search (go Implementation)
South China Industrial Group launched digital economy and successfully held the city chain technology conference
转卡通学习笔记
Curl --- the request fails when the post request parameter is too long (more than 1024b)
MySQL log management, backup and recovery of databases (1)
Skill combing [email protected] somatosensory manipulator
Action bright: take good care of children's eyes together -- a summary of the field investigation on the implementation of action bright in Guangxi
长城数艺数字藏品平台发布创世徽章
ArcGIS Pro + PS 矢量化用地规划图
Dyson design award, changing the world with sustainable design
mysql数据库基础:TCL事务控制语言
ArcGIS PRO + PS vectorized land use planning map
机器学习面试准备(一)KNN