1. 程式人生 > >Linux執行可執行檔案提示No such file or directory的解決方法

Linux執行可執行檔案提示No such file or directory的解決方法

最近在使用Linux作業系統執行一個可執行檔案,結果出現了No such file or directory的提示,表示很疑惑。

./tshrf

bash: ./tshref: No such file or directory

檢視檔案資訊,可以看到檔案是存在的,並且是可以執行的。

-rwxr-xr-x 1 yuan yuan 20581  429  2004 tshref

查閱資料後,原因是系統位數與該可執行檔案需要的lib庫位數不匹配。

用uname命令列印系統資訊,發現系統是64位系統

uname -a

Linux yuan-vm 3.13.0-32-generic
#57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

用file命令檢視檔案資訊,發現是一個32位可執行檔案。

file ./tshref

./tshref: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), 
dynamically linked (uses shared libs), for GNU/Linux 2.2.5, not stripped

要想在64位系統上與執行32位程式,則需要安裝32位lib庫。
對於Ubuntu使用者可以使用下面的命令安裝。

sudo apt-get install ia32-libs

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package ia32-libs is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the
following packages replace it: lib32z1 lib32ncurses5 lib32bz2-1.0

過程中有可能找不到需要的庫,但是會有幾個替代包,選擇安裝其中一個。

sudo apt-get install lib32bz2-1.0

lib32bz2-1.0

然後就可以正常執行之前的可執行檔案了。

遇到這種問題其實還有可能是其他原因,例如文字的編碼格式問題等,本文僅提出了一種解決方法,讀者遇到相同問題要具體問題具體分析。