尝试执行文件时出现"sh: ./<file> not found"错误
"sh: ./<file> not found" error when trying to execute a file
我遇到了一个我所遇到过的最奇怪的问题。我正在交叉编译ARM CPU与Linux板上的应用程序。我正在使用buildroot,一切都很顺利,直到我试图在目标上运行应用程序:我得到了-sh: ./hw: not found
。例如:
$ 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
)构建时,应用程序运行良好!
我通过readelf -a -W /tftpboot/hw
比较了可执行文件,但没有注意到太大的差异。我把两个输出都粘贴在这里。我唯一注意到的是Version5 EABI, soft-float ABI
对Version5 EABI
。我试图通过传递-mfloat-abi=softfp
和-mfloat-abi=soft
来消除差异,但编译器似乎忽略了它。不过,我想这并不重要,因为编译器甚至不会发出警告。
我还认为,如果可执行文件在某些方面不兼容,可能sh会输出此错误。但是在我的主机PC上,我看到了另一个错误,例如:
$ sh /tftpboot/hw
/tftpboot/hw: 1: /tftpboot/hw: Syntax error: word unexpected (expecting ")")
sh
打印这个奇怪的错误,因为它试图运行你的程序作为一个shell脚本!
你的错误./hw: not found
可能是由于没有找到动态链接器(又名ELF解释器)引起的。试着用-static
编译它作为一个静态程序,或者用你的动态加载器:# /lib/ld-linux.so.2 ./hw
或类似的东西运行它。
如果问题是动态加载器在你的工具链和运行时环境中的命名不同,你可以修复它:
- 在运行时环境中:带有符号链接。在工具链中:使用
-Wl,--dynamic-linker=/lib/ld-linux.so.2
相关文章:
- Seg Fault Issue C++ (file IO / getline)
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
- Visual Studio C++ Project File CustomBuild Task: Filter Outp
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- 可视化 如何在C++中将字符数组转换为 FILE 类型
- 如何在从文件中读取整数时使用 file.eof()?
- "No such file or directory" C++标头问题
- 使用 sftp_open() 使用 C++ 中的 SFTP libssh 将文件从本地复制到远程时,File 返回 N
- Visual Studio "fatal error LNK1104: cannot open file"未使用或包含的库
- typedef vector size_type in header file
- make 命令创建 .file,但不创建应用程序文件
- 为什么 VScode 在 .h 文件中显示"'iostream' file not found"?
- 我在 #include < bits/stdc++h.> 放置时出错"No such file or directory"
- 使用 编译时。RES File with MinGW G++, .无法识别 RES