linux加载动态库.so的3种方法

        昨天同事联系我,他部署新版本的MS软件提示找不到动态库。但是他能找到这个动态库文件,但不知道如何加载。这样的问题对于我来说是个再简单不过的问题,但对于一个新手,可能就是个打破头都不知道如何解决的问题。所以我想对这个简单问题,写个文章,希望对于刚接触这样的问题的同行有所启发。

         我了解的加载动态库,一共是三种方法。分别是将库放到/usr/lib64下;修改/etc/ld.so.conf以及在/etc/ld.so.conf.d下添加conf文件,将路径包装到该文件中。

         1:直接放到/etc/lib64下,然后用root用户调用ldconfig 加载生效。用ldconfig -v|grep xxx查看是否加载成功。

          

ln -s libvo-amrwbenc.so.0.0.4 libvo-amrwbenc.so
ln -s libopencore-amrnb.so.0.0.3 libopencore-amrnb.so
ln -s libx264.so.160 libx264.so
ln -s libunimrcpclient.so.0.5.0 libunimrcpclient.so
ln -s libasrclient.so.0.5.0 libasrclient.so
ln -s libunimrcpserver.so.0.5.0 libunimrcpserver.so
ln -s libapr-1.so.0.5.2 libapr-1.so
ln -s libaprutil-1.so.0.5.4 libaprutil-1.so
ln -s libsofia-sip-ua.so.0.6.0 libsofia-sip-ua.so
ln -s libunimrcpclient.so.0.5.0 libunimrcpclient.so
ln -s libunimrcpserver.so.0.5.0 libunimrcpserver.so
ln -s libexpat.so.0.5.0 libexpat.so

[ms@system-2-new etc]$ ldconfig -v|grep amr
ldconfig: Can't stat /libx32: No such file or directory
ldconfig: Path `/usr/lib' given more than once
ldconfig: Path `/usr/lib64' given more than once
ldconfig: Can't stat /usr/libx32: No such file or directory
ldconfig: /usr/local/lib/libavfilter.so.7 is not a symbolic link

ldconfig: /usr/local/lib/libavdevice.so.58 is not a symbolic link

ldconfig: /usr/local/lib/libpostproc.so.55 is not a symbolic link

ldconfig: /usr/local/lib/libavcodec.so.58 is not a symbolic link

        libopencore-amrwb.so.0 -> libopencore-amrwb.so.0.0.3
        libopencore-amrnb.so.0 -> libopencore-amrnb.so.0.0.3
ldconfig: /usr/local/lib/libavformat.so.58 is not a symbolic link
        libvo-amrwbenc.so.0 -> libvo-amrwbenc.so.0.0.4

ldconfig: /usr/local/lib/libswscale.so.5 is not a symbolic link

ldconfig: /usr/local/lib/libswresample.so.3 is not a symbolic link

ldconfig: /usr/local/lib/libavutil.so.56 is not a symbolic link

ldconfig: Can't create te

2:修改ld.so.conf文件,将动态库的目录放到改文件中,然后调用ldconfig加载,调用ldconfig -v|grep xxxx查看是否加载成功。

[ms@system-2-new etc]$ vi ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib/
/usr/local/unimrcp/lib/
/usr/local/apr/lib/
/usr/local/lib64/

ldconfig
ldconfig -v|grep amr

3:在/etc/ld.so.conf.d目录下创建文件,将动态库的文件路径放到conf文件中 

[ms@system-2-new etc]$ cd /etc/ld.so.conf.d
[ms@system-2-new ld.so.conf.d]$ ls
atlas-x86_64.conf    kernel-3.10.0-862.el7.x86_64.conf  llvm-x86_64.conf
dyninst-x86_64.conf  libiscsi-x86_64.conf               mariadb-x86_64.conf
[ms@system-2-new ld.so.conf.d]$ 
[ms@system-2-new ld.so.conf.d]$ vi mariadb-x86_64.conf
/usr/lib64/mysql

[root@system-2-new ~]# ldconfig -v|grep mysql
ldconfig: Can't stat /libx32: No such file or directory
ldconfig: Path `/usr/lib' given more than once
ldconfig: Path `/usr/lib64' given more than once
ldconfig: Can't stat /usr/libx32: No such file or directory
ldconfig: /usr/local/lib/libavfilter.so.7 is not a symbolic link

ldconfig: /usr/local/lib/libavdevice.so.58 is not a symbolic link

ldconfig: /usr/local/lib/libpostproc.so.55 is not a symbolic link

ldconfig: /usr/local/lib/libavcodec.so.58 is not a symbolic link

ldconfig: /usr/local/lib/libavformat.so.58 is not a symbolic link

ldconfig: /usr/local/lib/libswscale.so.5 is not a symbolic link

ldconfig: /usr/local/lib/libswresample.so.3 is not a symbolic link

ldconfig: /usr/local/lib/libavutil.so.56 is not a symbolic link

/usr/lib64/mysql:
        libmysqlclient.so.20 -> libmysqlclient.so.20.3.14
        libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
[root@system-2-new ~]# 

总结:

我了解的加载动态库,一共是三种方法。分别是将库放到/usr/lib64下;修改/etc/ld.so.conf以及在/etc/ld.so.conf.d下添加conf文件,将路径包装到该文件中。root下使用ldconfig命令加载生效,使用ldconfig -v|grep xxx进行查看是否生效。

你可能感兴趣的:(c/c++,shell基础知识及技巧,linux,运维,服务器)