我的C语言之路-----动态库和静态库
花了一下午时间来看动态库和静态的使用,还好都看懂了,而且都实验成功了linux 下静态库以.a结尾 动态库以.so结尾
下面是我的目录结构
main.c
stack3
stack.h
stack.c
pop.c
push.c
is_empty.c
1.静态库
cd stack3
gcc -c pop.c push.c stack.c is_empty.c
ar rs libstack.a *.o
cd ..
gcc main.c -L stack3 -lstack -Istack -o main
./main
2.动态库
cd stack3
gcc stack.c pop.c push.c is_empty.c -fPIC -shared -o libstack.so
(有些资料上写的 -c -o一起用,经测试不能一起用的)
cd ..
gcc main.o -L stack3 -lstack -Istack3 -o main
./main
(错误提示找不到libstack.so)
ldd main
(查看链接路径的时候也找不到)
cat /etc/ld.so.conf
(显示 include ld.so.conf.d/*.conf)
vim /etc/ld.so.conf.d/mytest.conf
(添加一行 /....../stack3/)
ldconfig
./main
(成功)
3.小知识
拷贝一个文件夹
cp -rf stack2 stack3
(不用mkdir stack3哦)呵呵,我是菜鸟,以前不知道
ps 我学习的资料大部分是linux c 一站式学习.pdf
页:
[1]