No such file or directory while executing existing binary

本文介绍了解决在Shell脚本中运行Binary时出现的“No such file or directory”错误的方法。该错误通常是因为缺少相应的动态加载器导致的。通过调整glibc编译过程中的共享库路径设置,可以确保Binary正确加载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在自动化构建toolchain的时候,在shell脚本中运行 binary 时,提示如下错误:

No such file or directory while executing existing binary

刚开始感觉很奇怪,在目录下能查看到对应的可执行文件,为什么就不能执行呢。而且用ldd $binary 的时候,显示this is not an executing binary 类似的语句,最后在archlinux上看到如下解释:

The file you'retrying to execute (/lmutil) exists but its loader doesn't exist, where

the loader of a nativeexecutable is its dynamic loader, for example /lib/ld-linux.so.2;

the loader of a script is theprogram mentioned on its shebang line, e.g., /bin/sh if the script begins with#!/bin/sh

大概的意思就是,这个excuting binary是存在,但是执行这个binary的解释器没有找到,shell脚本对应的解释器就是/bin/sh, 而binary的话对应的加载器就是/lib64/ld-linux-x86_64.so.2。

最后查找到的原因也是如此,发现我在构建toolchain过程中在/lib64下没有找到加载器,默认的加载器安装在了$prefix/usr/lib64下,然而用readelf $binary | grep interpreter, 发现需要的加载器路径为/lib64/ld-linux-x86_64.so.2。这个问题怎么办呢?

最后的解决办法是在编译glibc过程中指定shared library dir, 采用如下方法可以解决:

echo "slibdri=/lib64" > configparms , 强行指定共享库路径,然后对应的共享库便会安装在slibdir下。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值