bash: ./xxx: No such file or directory
问题现象
在使用开源或他人可执行文件的时候,可能会遇到 bash: ./squashfs2sparse: No such file or directory 的报错;实际测试发现该文件存在,并且有可执行权限;
问题分析
通过对报错文件的分析
1:文件具有可执行权限;
2:文件编译的系统和当前系统一致;x86-64
3:可执行文件依赖一个私人路径的.so库,在当前电脑是没有该路径的
# 文件执行报错
djq@huali-virtual-machine:~/linux_os/$ ./squashfs2sparse
bash: ./squashfs2sparse: No such file or directory
# 文件具有可执行权限
djq@huali-virtual-machine:~/linux_os/$ ls -lh squashfs2sparse
-rwxr-xr-x 1 djq huali 13K Jan 17 11:32 squashfs2sparse
# 文件依赖一个私人绝对路径的动态库 ld-linux-x86-64.so.2
djq@huali-virtual-machine:~/linux_os/$ file squashfs2sparse
back_squashfs2sparse: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /home/v1804/auto_build/apps_proc/build-qti-distro-tele-perf/tmp-glibc/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=1193336dc96c0c6bb7d19027812c9b511cf2278f, stripped
问题解决
我们可以使用 patchelf 工具,来修改 动态库的依赖路径;前提是个人环境下必须要有该动态库,才可以进行修改;
# ldd查看文件依赖的动态库
djq@huali-virtual-machine:~/linux_os/$ ldd squashfs2sparse
linux-vdso.so.1 (0x00007ffe1fbd0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f306e339000)
/home/v1804/auto_build/apps_proc/build-qti-distro-tele-perf/tmp-glibc/sysroots-uninative/x86_64-linux/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f306e743000)
# ls -lh 查看本机电脑相同动态库的路径
djq@huali-virtual-machine:~/linux_os/$ ls -lh /lib64/ld-linux-x86-64.so.2
lrwxrwxrwx 1 root root 32 May 1 2024 /lib64/ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.31.so
# patchelf 修改动态库的依赖路径
djq@huali-virtual-machine:~/linux_os/$ patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 squashfs2sparse
# file 再次查看文件依赖,已经没有了个人路径库
djq@huali-virtual-machine:~/linux_os/$ file squashfs2sparse
squashfs2sparse: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=1193336dc96c0c6bb7d19027812c9b511cf2278f, stripped
# 再次执行,可以执行成功
djq@huali-virtual-machine:~/linux_os/$ ./squashfs2sparse
squashfs_sparse - is used to prepare image which supports block update tested only for squashfs image .
squashfs_sparse is tested only for squashfs image, please check before using for any other fs type image
correct usage squashfs_sparse system.squash system.img
原文地址:https://blog.csdn.net/dujunqiu/article/details/145204464
免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!