当前位置:网站首页>静态库的制作和使用
静态库的制作和使用
2022-06-28 10:51:00 【MoyangCitta】
库文件
库是一组预先编译好的方法的集合。 Linux 系统存储的库的位置一般在: /lib 和 /usr/lib。
在 64 位的系统上有些库也可能被存储在/usr/lib64 下。库的头文件一般会被存储在
/usr/include 下或其子目录下。
库有两种,一种是静态库,其命令规则为 libxxx.a,一种是共享库,其命令规则为 libxxx.so。
静态库的生成
a.c b.c head.h以上是需要生成静态库的“.c”文件,其中“head.h”中是函数的声明,“a.c”,“b.c”是函数的定义
1.将需要生成库的文件的所有“.c”文件编译成“.o”文件
gcc -c a.c
gcc -c b.c2.使用ar命令将第一步生成的所有“.o”文件生成静态库
ar crv libab.a a.o b.o其中:c是创建库;r是将方法添加到库中;v显示过程
静态库的使用
#include "head.h"测试代码中需要包含指定的库文件
gcc test.c -o test -L. -lhead- -L:指定库的存储路径
- -l:指定库的名称(不需要前面的‘lib’和扩展名‘.a’)
项目目录
- include:存放项目的头文件
- lib:库文件
- src:源代码文件
项目中静态库的使用
结构图如下所示

1.将src中需要生成库的文件的所有“.c”文件编译成“.o”文件,需要注意头文件在include中,因此在编译时需要指定include包含文件的搜索目录。
gcc -c add.c sub.c mult.c div.c -I ../include/2.使用ar命令将第一步生成的所有“.o”文件生成静态库,需要指定lib文件夹
ar rcs ../lib/libcalc.a add.o div.o mult.o sub.o3. 链接:需要指定include文件夹的头文件以及指定库文件的位置以及库文件的名称
gcc main.c -o main -I ./include/ -L ./lib -l calc边栏推荐
- Resolution: overview of decentralized hosting solution
- How to use K-line diagram for technical analysis
- Mongo数据库
- [unity][ecs] learning notes (III)
- 广州海关支持保障食品、农产品和中药材等民生物资稳定供港
- Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
- Ribbon core source code analysis
- Realization of a springboard machine
- DlhSoft Kanban Library for WPF
- Idea failed to connect to SQL Sever
猜你喜欢

Teach you how to handle the reverse SVG mapping of JS

数据库系列:有什么办法对数据库的业务表进行无缝升级

Spatial-Temporal时间序列预测建模方法汇总

Move command

爱可可AI前沿推介(6.28)

Debug debugging in katalon

【实操】Appium Settings app is not running after 5000ms
![[unity] built in rendering pipeline to URP](/img/a5/3ae37b847042ffb34e436720f61d17.png)
[unity] built in rendering pipeline to URP

无线模块透明传输技术的物联网应用案例

Katalon framework tests web (XX) custom keywords and upload pop-up operations
随机推荐
实体转JSON时,值为null的字段的丢失问题
Summary of spatial temporal time series prediction modeling methods
JS基础8
【monkey】monkey测试入门
Yann LeCun新论文:构建自动智能体之路
JSON module, hashlib, Base64
JSON模块、hashlib、base64
Ribbon core source code analysis
DlhSoft Kanban Library for WPF
无线模块透明传输技术的物联网应用案例
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
AQS理解
建立自己的网站(11)
Katalon framework tests web (XX) custom keywords and upload pop-up operations
拼接String集合中的字符串_基于Stream
Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
File的io流与base64
MySQL common commands for viewing database performance
Mysql通用二进制安装方式
[Unity]EBUSY: resource busy or locked