当前位置:网站首页>Making and using of static library
Making and using of static library
2022-06-28 11:01:00 【MoyangCitta】
The library files
A library is a collection of precompiled methods . Linux The location of the system repository is generally : /lib and /usr/lib.
stay 64 Some libraries on a bit system may also be stored in /usr/lib64 Next . The header file of the library is usually stored in
/usr/include Or its subdirectories .
There are two kinds of libraries. , One is a static library , The command rule is libxxx.a, One is the shared library , The command rule is libxxx.so.
Generation of static library
a.c b.c head.hThe above is to generate a static library “.c” file , among “head.h” Is the declaration of the function ,“a.c”,“b.c” Is the definition of a function
1. Will need to generate all of the library's files “.c” File compiled into “.o” file
gcc -c a.c
gcc -c b.c2. Use ar The command will all the... Generated in the first step “.o” File generation static library
ar crv libab.a a.o b.oamong :c Is to create a library ;r Is to add methods to the library ;v Show the process
The use of static libraries
#include "head.h"The test code needs to contain the specified library file
gcc test.c -o test -L. -lhead- -L: Specify the storage path of the library
- -l: Specify the name of the library ( There is no need for the front ‘lib’ And extension ‘.a’)
Project directory
- include: Store the header file of the project
- lib: The library files
- src: Source code file
Use of static libraries in the project
The structure diagram is shown below

1. take src All the files that need to generate the library in “.c” File compiled into “.o” file , Note that the header file is in the include in , Therefore, you need to specify include Search directory containing files .
gcc -c add.c sub.c mult.c div.c -I ../include/2. Use ar The command will all the... Generated in the first step “.o” File generation static library , You need to specify the lib Folder
ar rcs ../lib/libcalc.a add.o div.o mult.o sub.o3. link : You need to specify the include The header file of the folder and specify the location of the library file and the name of the library file
gcc main.c -o main -I ./include/ -L ./lib -l calc边栏推荐
- fastposter v2.8.4 发布 电商海报生成器
- Solve the problem of reading package listsdonebuilding dependency treereading state informationdone
- Convert the file URL in the browser to a file stream
- JS foundation 3
- 一套十万级TPS的IM综合消息系统的架构实践与思考
- 什么是主链系统?
- 利用soapUI获取freemarker的ftl文件模板
- Mysql database overview and installation process
- metersphere使用js刷新当前页面
- Compareto() and equals() methods of BigDecimal class
猜你喜欢

vsftpd服务的部署及优化

Realization of a springboard machine

Threads and thread pools

字符串 & 堆 & 方法区

JS foundation 3

【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)

树莓派无需显示屏的VNC Viewer方式的远程连接
This Exception was thrown from a job compiled with Burst, which has limited exception support. 报错

sentinel

Ruoyi integrated building block report (NICE)
随机推荐
Minimum stack < difficulty coefficient >
Katalon框架测试web(二十)自定义关键字以及上传弹窗操作
Realization of a springboard machine
字符串 & 堆 & 方法区
Dataease installation upgrade
Datetime and logging module
MySQL (II)
【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
什么是主链系统?
Set up your own website (11)
阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
Katalon framework tests web (XX) custom keywords and upload pop-up operations
Spatial-Temporal时间序列预测建模方法汇总
压缩解压
Katalon global variable is referenced in testobject
Yann LeCun新论文:构建自动智能体之路
vsftpd服务的部署及优化
MySQL (III)
Metersphere implements UI automation elements that are not clickable (partially occluded)
Katalon framework tests a web page operation example code