当前位置: 首页 > article >正文

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

http://www.kler.cn/a/519094.html

相关文章:

  • Cesium特效——城市白模的科技动效的各种效果
  • http和ws的区别
  • 【设计模式-行为型】调停者模式
  • libOnvif通过组播不能发现相机
  • 51单片机入门_01_单片机(MCU)概述(使用STC89C52芯片)
  • SpringBoot3+Vue3开发学生选课管理系统
  • CSS 中的 id 和 class 选择器
  • ARM嵌入式学习--第九天(串口通信)
  • 二十三种设计模式-享元模式
  • minikube源码学习
  • 【自然语言处理(NLP)】jieba分词的使用(分词模式、关键词提取)
  • 【BQ3568HM开发板】深入解析智能家居中控屏工程的NAPI接口设计
  • 视觉语言模型 (VLMs):跨模态智能的探索
  • [ACTF2020 新生赛]BackupFile1
  • 【Redis】在ubuntu上安装Redis
  • 每天五分钟深度学习框架pytorch:搭建谷歌的Inception网络模块
  • Elastic Agent 对 Kafka 的新输出:数据收集和流式传输的无限可能性
  • CSS(二)——选择器
  • 个人网站搭建
  • 基于Flask的北京房屋租赁管理系统的设计与实现