0x00问题出现场景
编写代码调用了动态库的函数,linux是要加载到环境中,所以引用动态库头文件并没有真正的使用到动态库,当编译代码,就会报以下的错误
[root@localhost netproc]# ./client
./client: error while loading shared libraries: libitcastsocket.so: cannot open shared object file: No such file or directory
错误提示很明显提示没有找到动态库。
0x01检测程序有那些没有加载的动态库
[root@localhost netproc]# ldd client
linux-vdso.so.1 => (0x00007fff6f9ff000)
libitcastsocket.so => not found
libc.so.6 => /lib64/libc.so.6 (0x0000003a64000000)
/lib64/ld-linux-x86-64.so.2 (0x0000003a63800000)
0x02加载缺失的动态库
直接将文件目录下的动态库加载到环境中
export LD_LIBRARY_PATH=/netproc:$LD_LIBRARY_PATH[root@localhost netproc]# ldd client
linux-vdso.so.1 => (0x00007fffd43ff000)
libitcastsocket.so => /netproc/libitcastsocket.so (0x00007f65fbf91000)
libc.so.6 => /lib64/libc.so.6 (0x0000003a64000000)
/lib64/ld-linux-x86-64.so.2 (0x0000003a63800000)
在Linux下编写代码调用动态库时,如果未正确加载,运行会报错。通过检查程序缺失的动态库并手动加载到环境中可以解决问题。本文介绍了如何检测未加载的动态库及如何加载缺失的库。
2万+

被折叠的 条评论
为什么被折叠?



