当前位置:网站首页>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边栏推荐
- 论文阅读 (59):Keyword-Based Diverse Image Retrieval with Variational Multiple Instance Graph
- JS foundation 4
- 方法重写(Override)
- 【实操】Appium Settings app is not running after 5000ms
- Word、PDF、TXT文件实现全文内容检索需要用什么方法?
- 数据库系列:有什么办法对数据库的业务表进行无缝升级
- Does flink1.15 support MySQL views? I configured the view name at the table name to save, but the table could not be found. Think
- AQS understanding
- Mysql安装配置以及解决重装Mysql时忘记root password问题
- Guangzhou Customs supports the stable supply of food, agricultural products, traditional Chinese medicine and other civilian and biological resources to Hong Kong
猜你喜欢

还在用 SimpleDateFormat 做时间格式化?小心项目崩掉!

远程登录sshd服务

Katalon framework tests web (XX) custom keywords and upload pop-up operations

sentinel

MySQL general binary installation method

Summary of spatial temporal time series prediction modeling methods
![[Li Kou - dynamic planning] sort out topic 1: basic topics: 509, 70, 746, 62, 63, 343, 96 (with links, topic descriptions, problem solving methods and codes)](/img/02/4dbd97c8b8df1c96b7c8e1460aeda2.png)
[Li Kou - dynamic planning] sort out topic 1: basic topics: 509, 70, 746, 62, 63, 343, 96 (with links, topic descriptions, problem solving methods and codes)

JS foundation 3

线程和线程池

Ble Bluetooth module nrf518/nrf281/nrf528/nrf284 chip scheme comparison
随机推荐
JS基础1-JS引入与运算符
Summary of characteristics of five wireless transmission protocols of Internet of things
JS foundation 3
Blackmail virus of industrial control security
利用soapUI获取freemarker的ftl文件模板
MySQL查看数据库性能常用命令
JS基础5
Compression and decompression
SQL中的DQL、DML、DDL和DCL是怎么区分和定义的
MySQL (I)
什么是主链系统?
【Qt】connect 语法参考实现
[QT] connect syntax reference implementation
MySQL (II)
Excel导入导出便捷工具类
Makefile简介
移动命令
Internet of things application case of wireless module transparent transmission technology
[practice] appium settings app is not running after 5000ms
一套十万级TPS的IM综合消息系统的架构实践与思考