当前位置:网站首页>静态库的制作和使用
静态库的制作和使用
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边栏推荐
- sentinel
- JS基础1-JS引入与运算符
- JS基础6
- Katalon当中的debug调试
- Secretary of the Ukrainian national security and National Defense Commission: will carry out precision strikes against targets in Russia
- Set up your own website (11)
- [function suggestion] select a space when multiple workspaces are started
- Installing MySQL database (CentOS) in Linux source code
- An idea plug-in that automatically generates unit tests, which improves the development efficiency by more than 70%!
- JSON module, hashlib, Base64
猜你喜欢
![[unity][ecs] learning notes (II)](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[unity][ecs] learning notes (II)

vsftpd服务的部署及优化

港伦敦金行情走势图所隐藏的信息

Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison

How to use output in katalon

Summary of spatial temporal time series prediction modeling methods

Teach you how to handle the reverse SVG mapping of JS

Katalon全局变量在TestObject引用

Threads and thread pools

MySQL (I)
随机推荐
Several methods of using ABAP to operate Excel
Metersphere uses JS to refresh the current page
物联网5种无线传输协议特点大汇总
Who knows if it is safe to open an account with CSC securities
Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
Metersphere implements UI automation elements that are not clickable (partially occluded)
JS基础8
Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
[function suggestion] select a space when multiple workspaces are started
Katalon全局变量在TestObject引用
[leetcode daily question] [December 19, 2021] 997 Find the town judge
Fabric. How to use js brush?
June training (day 28) - Dynamic Planning
[QT] connect syntax reference implementation
Remote connection of raspberry pie in VNC viewer mode without display
linux中源码安装mysql数据库(centos)
Training and recognition of handwritten digits through the lenet-5 network built by pytorch
JS基础2
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
Katalon global variable is referenced in testobject