gcc生成静态库.a和动态库.so
(一)hello实例使用库
参考博主:gcc生成静态库.a和动态库.so_c源文件转换为a静态库-优快云博客
1.前置工作准备:
(1).创建一个目录week3
(2).指令
hello.h
hello.c
main.c
gcc编译
2.静态库使用
创建静态库指令ar
以lib作为前缀.a文件
ar -crv libmyhello.a hello.o
3.动态库使用
创建动态库指令gcc
gcc -shared -fPIC -o libmyhello.so hello.o
创建:
执行hello文件出错
sudo解决
实例
1.代码部分
main1.c
sub.h
sub1.c
sub2.c
gcc编译:gcc -c sub1.c sub2.c
静态库
动态库
gcc -shared -fPIC libsub.so sub1.o sub2.o
gcc -o main1 main1.c libsub.so