2016年2月22日 星期一

error while loading shared libraries

error while loading shared libraries

錯誤訊息example

./openwsmand: error while loading shared libraries: libwsman_server.so.1: cannot open shared object file: No such file or directory

這篇的重點在兩個 1. 指令 ldconfig  2. lib 說明文件 /etc/ld.so.conf 和 /etc/ld.so.cache

1)如果共享庫文件安裝到了/lib或/usr/lib目錄下,那麼需執行一下ldconfig命令 
ldconfig命令的用途,主要是在預設搜尋目錄(/lib和/usr/lib)以及 etc/ld.so.conf內所列的目錄下,搜索出可共享的dynamic library(格式如lib*.so*),進而創建出動態裝入程序(ld.so)所需的連接和緩存文件.緩存文件默認為/etc/ld.so.cache,此文件保存已排好序的動態鏈接庫名字列表.

2)如果共享庫文件安裝到了/usr/local/lib(很多opensource的shared library都會安裝到該目錄下)或其它"非/lib或/usr/lib"目錄下,那麼在執行ldconfig命令前,還要把新shared library目錄加入到共享庫配置文件/etc/ld.so.conf中,如下:
cat /etc/ld.so.conf 
include ld.so.conf.d/*.conf 
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

3)如果shared library安裝到了其它"非/lib或/usr/lib"目錄下,但是又不想在/etc/ld.so.conf中加路徑(或者是沒有權限加路徑).那可以export一個Global變數 LD_LIBRARY_PATH ,然後運行程序的時候就會去這個目錄中找shared library.
LD_LIBRARY_PATH的意思是告诉loader在哪些目录中可以找到shared library. 可以設定多個搜索目錄, 這些目錄之間用冒號分隔開. 比如安装了一个mysql到/usr/local/mysql目錄下, 其中有一大堆shared library在/usr/local/mysql/lib下面, 則可以在.bashrc或.bash_profile或shell里加入以下:

export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH

一般來講這只是一種臨時的解決方案,在沒有權限或臨時需要的時候使用

4)如果程序需要的庫文件比系統目前存在的村文件版本低,可以做一個鏈接比如:
error while loading shared libraries: libncurses.so.4: cannot open shared object file: No such file or directory 
ls /usr/lib/libncu*
/usr/lib/libncurses.a   /usr/lib/libncurses.so.5
/usr/lib/libncurses.so  /usr/lib/libncurses.so.5.3

可见虽然没有libncurses.so.4,但有libncurses.so.5,是可以向下兼容的
建一个链接就好了
ln -s  /usr/lib/libncurses.so.5.3  /usr/lib/libncurses.so.4

ref: http://blog.chinaunix.net/uid-26212859-id-3256667.html

沒有留言:

張貼留言