錯誤"error while loading shared libraries: xxx.so.x" 的原因和解決辦法
一般我們在Linux下執行某些外部程式的時候可能會提示找不到共享庫的錯誤,比如:
error while loading shared libraries: libprotobuf.so.9: cannot open shared object file: No such file or directory
原因一般有兩個,一個是作業系統裡確實沒有包含該共享庫(lib*.so.*檔案)或者共享庫版本不對,遇到這種情況那就去網上下載並安裝上即可。
另外一個原因就是已經安裝了該共享庫,但執行需要呼叫該共享庫的程式的時候,程式按照預設共享庫路徑找不到該共享庫檔案。
如上圖,編譯、執行protobuf示例程式碼時報該錯,但在目錄/usr/local/lib下我們可以看到libprotobuf.so.9是存在的:
所以安裝共享庫後要注意共享庫路徑設定問題,如下:
1)如果共享庫檔案安裝到了/lib或/usr/lib目錄下, 那麼需執行一下ldconfig命令。
ldconfig命令的用途,主要是在預設搜尋目錄(/lib和/usr/lib)以及動態庫配置檔案/etc/ld.so.conf內所列的目錄下,搜尋出可共享的動態連結庫(格式如lib*.so*),進而建立出動態裝入程式(ld.so)所需的連結和快取檔案。快取檔案預設為/etc/ld.so.cache,此檔案儲存已排好序的動態連結庫名字列表。
2)如果共享庫檔案安裝到了/usr/local/lib(很多開源的共享庫都會安裝到該目錄下)或其它“非/lib或/usr/lib”目錄下,那麼在執行ldconfig命令前,還要把新共享庫目錄加入到共享庫配置檔案/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)如果共享庫檔案安裝到了其它“非/lib或/usr/lib”目錄下, 但是又不想在/etc/ld.so.conf中加路徑(或者是沒有許可權加路徑)。那麼可以export一個全域性變數LD_LIBRARY_PATH,然後執行程式的時候就會去這個目錄中找共享庫。
LD_LIBRARY_PATH的意思是告訴loader在哪些目錄中可以找到共享庫。可以設定多個搜尋目錄,這些目錄之間用冒號分隔開。比如安裝了一個mysql到/usr/local/mysql目錄下,其中有一大堆庫檔案在/usr/local/mysql/lib下面,則可以在.bashrc或.bash_profile或shell里加入以下語句:
export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH
一般來講這只是一種臨時的解決方案,在沒有許可權或臨時需要的時候使用。
相關文章
- error while loading shared libraries: xxx.so.x"錯誤的原因和解決辦法ErrorWhile
- "error while loading shared libraries: xxx.so.x" 錯誤的原因和解決辦法ErrorWhile
- error while loading shared libraries 錯誤解決辦法總結ErrorWhile
- error while loading shared librariesErrorWhile
- 錯誤 error while loading shared libraries: libclntsh.so.9.0 的解決ErrorWhile
- 使用SRVCTL時報錯:error while loading shared librariesErrorWhile
- 解決"error while loading shared libraries: libclntshErrorWhile
- Mysql的error while loading shared libraries解決方法MySqlErrorWhile
- MySQL 啟動報錯 error while loading shared librariesMySqlErrorWhile
- ./ggsci: error while loading shared librariesErrorWhile
- sqlplus: error while loading shared librariesSQLErrorWhile
- sqlplus: error while loading shared libraries的解決方案SQLErrorWhile
- 【故障處理】csscan工具無法使用,報錯“error while loading shared libraries...”CSSErrorWhile
- error while loading shared libraries: libaio.so.1ErrorWhileAI
- Error while loading shared libraries: libssl.so.6:ErrorWhile
- 故障解決:error while loading shared libraries: libncurses.so.5ErrorWhile
- [mysql]error while loading shared libraries: libaio.so.1: 解決方案MySqlErrorWhileAI
- mongod: error while loading shared libraries: libstdc++.so.6GoErrorWhileC++
- error while loading shared libraries: libclntsh.so.10.1ErrorWhile
- innobackupex: error while loading shared libraries: libssl.so.6ErrorWhile
- glodengate配置時報ggsci: error while loading shared librariesErrorWhile
- ORACLE SQLPLUS 報 error while loading shared libraries[轉]OracleSQLErrorWhile
- error while loading shared libraries: libcap.so.1: cannot open sharedErrorWhile
- MongoDB報錯mongorestore: error while loading shared libraries: libsasl2.so.2MongoDBRESTErrorWhile
- error while loading shared libraries: libgsl.so.27: cannot open shared objectErrorWhileObject
- error while loading shared libraries: libgconf-2.so.4:ErrorWhileGC
- ggsci: error while loading shared libraries: libnnz11.soErrorWhile
- error while loading shared libraries: libstdc++.so.5: cannot openErrorWhileC++
- csscan: error while loading shared libraries: libclntsh.so.10.1CSSErrorWhile
- sqlldr執行報錯:error while loading shared libraries: libclntsh.so.10.1:SQLErrorWhile
- error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No suchErrorWhileIBMMySqlclientObject
- sqlplus: error while loading shared libraries: libaio.so.1:SQLErrorWhileAI
- MySQL 5.7初始化報錯error while loading shared libraries: libnuma.so.1MySqlErrorWhile
- 伺服器出現500錯誤的原因和解決辦法伺服器
- sqlplus: error while loading shared libraries: libsqlplus.soSQLErrorWhile
- Error while loading shared libraries: libreadline.so.7: cannot open shared objecErrorWhileOBJ
- error while loading shared libraries: libodm9.so: cannot open shared object file: No such file or diErrorWhileObject
- 執行csscan出現loading shared libraries錯誤CSS