Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux 執行程式提示 error while loading shared libraries 解決方案

編輯:關於 Linux

執行二進位程式時出現 error while loading shared libraries: xxx.so.0: cannot open shared object file: No such file or directory,表示動態連結器 ld.so 在預設搜尋路徑(/lib、/usr/lib、/etc/ld.so.conf 所列目錄)找不到所需的共享庫。

一、快速定位庫檔位置

# 常見第三方庫安裝位置
find /usr/local -name "xxx.so*"
find /opt -name "xxx.so*"
# 或使用 locate(需 updatedb)
locate xxx.so

二、將庫目錄加入動態連結器設定

  1. 編輯 /etc/ld.so.conf(或在 /etc/ld.so.conf.d/ 新增 custom.conf),新增庫所在目錄(如 /usr/local/lib):
/usr/local/lib
  1. 更新快取:
sudo ldconfig -v

-v 會顯示掃描到的庫與建立的快取連結。

三、臨時替代方案(不修改系統設定)

# 單次執行指定庫路徑
LD_LIBRARY_PATH=/usr/local/lib ./your_program

# 或寫入啟動腳本
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

四、驗證程式相依庫

ldd ./your_program
# 輸出範例
linux-vdso.so.1 =>  (0x00007ffc12345000)
xxx.so.0 => /usr/local/lib/xxx.so.0 (0x00007f1234567000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1234568000)
# 若顯示 "not found" 即為缺少該庫

shared library error 示意圖

將第三方庫目錄(通常為 /usr/local/lib)加入 /etc/ld.so.conf 並執行 ldconfig,即可永久解決 error while loading shared libraries 問題。

Copyright © Windows教程網 All Rights Reserved