Ubuntu18.04可执行文件运行提示No such file or directory

时间:2022-12-28 12:36:07

参考原文见

https://blog.csdn.net/sun927/article/details/46593129?

最近我也遇到一个类似问题,同一个工具在Ubuntu16.04里面运行是好的,但是Ubuntu18.04运行就出错了。

我用file也看了是32bit的应用程序,但一直没想到Ubuntu18.04竟然默认去掉了32bit的library。

用uname命令打印系统信息,发现系统是64位系统

$ uname -a
Linux latitude-e5440 5.3.0-40-generic #32~18.04.1-Ubuntu SMP Mon Feb 3 14:05:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

安装ia32-libs,提示找不到了,候选lib32ncurses5或lib32z1,我用了lib32z1.

 sudo apt-get install ia32-libs
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:
lib32ncurses5 lib32z1 E: Package 'ia32-libs' has no installation candidate
$ sudo apt-get install lib32z1

另外,如果用到32bit的libstdc++6,应该是安装

lib32stdc++6。

顺便看了一下查询用到的so,有两种办法

之一是ldd命令

ldd ./combine-image
linux-gate.so.1 (0xf7f63000)
libc.so.6 => /lib32/libc.so.6 (0xf7d71000)
/lib/ld-linux.so.2 (0xf7f64000)

之二是readelf -d

readelf -d  ./combine-image

Dynamic section at offset 0x7f20 contains 21 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [libc.so.6]
0x0000000c (INIT) 0x8048880

调用的是32bit的libc.so。

之前有部分应用不能运行估计也是这个原因。

不知道这个方法是不是可以适合WSL