1.生成so
gcc -shared -o libmyCalc.so *.o
2。生成myAPp
[root@localhost c]# gcc main.c -Iinclude -L./lib -lmyCalc -o myapp
[root@localhost c]# ll
total 36
drwxr-xr-x. 2 root root 25 Jul 11 07:43 lib
-rw-r--r--. 1 root root 1646 Jul 11 06:33 libmy.a
-rwxr-xr-x. 1 root root 8001 Jul 11 06:27 libmyCalc.so
-rw-r--r--. 1 root root 1646 Jul 11 04:21 libmytest.a
-rw-r--r--. 1 root root 118 Jul 11 04:20 main.c
-rw-r--r--. 1 root root 1504 Jul 11 06:32 main.o
-rwxr-xr-x. 1 root root 8510 Jul 11 07:43 myapp
[root@localhost c]# ldd myapp
linux-vdso.so.1 => (0x00007fff11ffd000)
libmyCalc.so => not found
libc.so.6 => /lib64/libc.so.6 (0x00007f01da8fd000)
/lib64/ld-linux-x86-64.so.2 (0x00007f01dacc8000)
[root@localhost c]#
3.引用动态库
[root@localhost c]# export LD_LIBRARY_PATH=./lib
[root@localhost c]# ldd myapp
linux-vdso.so.1 => (0x00007ffdb3df9000)
libmyCalc.so => ./lib/libmyCalc.so (0x00007f2f2ca4c000)
libc.so.6 => /lib64/libc.so.6 (0x00007f2f2c682000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2f2cc4f000)
[root@localhost c]#
4.永久添加
~目录的 vi .bashrc
vi .bashrc 把固定路由写进去
export LD_LIBRARY_PATH=/home/c/lib
网友评论