“sh:./<file>未找到“尝试执行文件时出错 [英] "sh: ./<file> not found" error when trying to execute a file

查看:302
本文介绍了“sh:./<file>未找到“尝试执行文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个我遇见的最奇怪的问题。我试图交叉编译一个应用程序的ARM CPU与linux板载。我使用的是< em> buildroot ,所有都很好,直到我加载一个应用程序到目标。当我试图启动一个应用程序,我得到一个错误,如 -sh:./hw:not found 。让我们考虑一个例子

I've come across a weirdest problem I ever met. I am trying to cross-compile an app for the ARM CPU with a linux on-board. I am using the buildroot, and all goes just fine, until I load an application to the target. When I am trying to launch an application, I getting an error like -sh: ./hw: not found. Let's consider an example

$ cat /tmp/test.cpp 
#include <cstdio>
#include <vector>

int main(int argc, char** argv){
        printf("Hello Kitty!\n");
        return 0;
}
$ ./arm-linux-g++ -march=armv7-a /tmp/test.cpp -o /tftpboot/hw

将可执行文件加载到目标;下一个目标发出:

# ./hw
-sh: ./hw: Permission denied
# chmod +x ./hw
# ./hw
-sh: ./hw: not found
# ls -l ./hw
-rwxr-xr-x    1 root     root          6103 Jan  1 03:40 ./hw

高。如果我通过发行版编译器编译,像这样 arm-linux-gnueabi-g ++ -march = armv7 -a /tmp/test.cpp -o / tftpboot / hw 应用程序运行很好!

But yet it isn't all. If I compile by the distro compiler, like this arm-linux-gnueabi-g++ -march=armv7-a /tmp/test.cpp -o /tftpboot/hw, the application runs just fine!

我试图通过 readelf -a -W / tftpboot / hw ,但没有注意到任何大的差异。我在此处粘贴了两个输出。我注意到的唯一的是线 Version5 EABI,软浮动ABI vs Version5 EABI 。我试图通过传递任一选项 -mfloat-abi = softfp -mfloat-abi = soft ,但编译器似乎只是忽略它。但是,我想,这并不重要,因为编译器甚至不警告我。

I tried to compare the files through the readelf -a -W /tftpboot/hw, but haven't noticed any big defferences. I pasted both the outputs here. The only thing I had noticed is the lines Version5 EABI, soft-float ABI vs Version5 EABI. I tried to remove this line too, by passing either of the options -mfloat-abi=softfp and -mfloat-abi=soft, but compiler seems just ignore it. But, I suppose, this doesn't really matter, as the compiler doesn't even warn me.

还有一件事:起初我认为 sh 写这个奇怪的错误,如果可执行文件某种不兼容。但这不是真的!在我的主机PC上, sh 在此情况下会出现另一个错误,例如:

One more thing: at first I thought that the sh writes this weird error if the executable file somehow incompatible. But this is not true! On my host PC the sh gives another error in this cases, i.e.:

$ sh /tftpboot/hw
/tftpboot/hw: 1: /tftpboot/hw: Syntax error: word unexpected (expecting ")")

$ b b

推荐答案

打印这个奇怪的错误,因为它试图作为一个 shell

sh prints this weird error because it is trying to run your program as a shell script!

您的错误 ./ hw:not found 可能是由动态链接器AKA ELF解释器)。尝试使用 -static 将其编译为静态程序,或使用动态加载器运行它:#/lib/ld-linux.so.2 ./

Your error ./hw: not found is probably caused by the dynamic linker (AKA ELF interpreter) not being found. Try compiling it as a static program with -static or running it with your dynamic loader: # /lib/ld-linux.so.2 ./hw or something like that.

如果问题是动态加载器在工具链和运行时环境中命名不同,可修复它:

If the problem is that the dynamic loader is named differently in your tool-chain and in your runtime environment you can fix it:


  • 在运行时环境中:带有符号链接。

  • -chain:use -Wl, - dynamic-linker = / lib / ld-linux.so.2

  • In the runtime environment: with a symbolic link.
  • In the tool-chain: use -Wl,--dynamic-linker=/lib/ld-linux.so.2

这篇关于“sh:./&lt;file&gt;未找到“尝试执行文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆