[置顶] linux学习之静态库和动态库的制作与使用

linux中静态库和动态库的制作与使用

一、静态链接库

1、首先编写模块程序example.c、example.h

2、使用gcc -c example.c -o example.o编译example.c

3、使用命令 ar cqs libexample.a example.o对库进行打包,完成后使用命令 cp libexample.a /usr/lib 完成转移

4、创建test.c文件,编译 gcc  -lexample(指定链接库名称) test.c -o  test  完成。


二、动态链接库

1、首先编写模块程序example.c、example.h

2、使用gcc -c example.c -o example.o编译example.c

3、使用命令gcc  -shared  -fPIC  example.o -o libexample.so,完成后使用命令 cp libexample.so /usr/lib 完成转移

4、创建test.c文件,编译 gcc  -lexample(指定链接库名称) test.c -o  test  完成。



原文地址:https://www.cnblogs.com/snake-hand/p/3190188.html