当前位置:网站首页>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边栏推荐
猜你喜欢
随机推荐
【Qt】connect 语法参考实现
Katalon global variable is referenced in testobject
JS foundation 3
Blue Bridge Cup Maze (dfs+ backtracking)
[Agora] get an Agora_ Example usage of refptr object
阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
建立自己的网站(11)
MytipartFile与File的相互转换
ICMP协议的作用,Ping of Death攻击的原理是什么?
Yann LeCun新论文:构建自动智能体之路
JS foundation 2
Markdown -- basic usage syntax
个人买场内基金选择什么证券公司开户好,更安全
【实操】Appium Settings app is not running after 5000ms
压缩解压
GCC简介
Hystrix 部署
【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
乌国家安全与国防委员会秘书:将对俄境内目标进行精确打击
Mongo database








