https://www.cnblogs.com/MYSQLZOUQI/p/5901765.html
[email?protected]:mygcc$ ls
libmytest.a? main??? my_so_test.h? st1.o? st2.o???? test_a.o? test_b.o? test_c.o
libtest.so?? main.c? st1.c???????? st2.c? test_a.c? test_b.c? test_c.c
[email?protected]:mygcc$ cat test_*.c
#include "my_so_test.h"
void testA()
{
??? printf("In AAAn");
}
#include "my_so_test.h"
void testB()
{
??? printf("In BBBn");
}
#include "my_so_test.h"
void testC()
{
??? printf("In CCCn");
}
[email?protected]:mygcc$ cat test_
test_a.c? test_a.o? test_b.c? test_b.o? test_c.c? test_c.o ?
[email?protected]:mygcc$ cat my_so_test.h
#include <stdio.h>
void testA();
void testB();
void testC();
[email?protected]:mygcc$ gcc -shared -fPIC -o libtest.so test_*.o
[email?protected]:mygcc$ gcc main.c -L . -ltest? -o main
[email?protected]:mygcc$ ldd main
?? ?linux-vdso.so.1 =>? (0x00007ffe6d7fc000)
?? ?libtest.so => /usr/download/test/mygcc/libtest.so (0x00007fac1c26c000)
?? ?libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fac1bea2000)
?? ?/lib64/ld-linux-x86-64.so.2 (0x00007fac1c46e000)
[email?protected]:mygcc$ 偶忍不住又要罗嗦一句了,相信俺,我的唠叨对大家是有好处。我为什么用这种方法呢?因为我是在给大家演示动态库的用法,完了之后我就把libtest.so给删了,然后再重构ld.so.cache,对我的系统不会任何影响。倘若我是开发一款软件,或者给自己的系统DIY一个非常有用的功能模块,那么我更倾向于将libtest.so拷贝到/lib、/usr/lib目录下,或者我还有可能在/usr/local/lib/目录下新建一文件夹xxx,将so库拷贝到那儿去,并在/etc/ld.so.conf.d/目录下新建一文件mytest.conf,内容只有一行“/usr/local/lib/xxx/libtest.so”,再执行ldconfig。如果你之前还是不明白怎么解决那个“not found”的问题,那么现在总该明白了吧。