我编写了简单的Hello world程序并使用gcc-arm-linux-gnueabi
编译器编译它。它编译得很好,但是当我尝试在ARM机器上执行它时,它会抱怨"没有这样的文件或目录"。我认为gcc-arm-linux-gnueabi
仅适用于嵌入式Linux,因为e(mbedded)abi。它与ARM Linux ABI不同吗?
请帮我解决这个问题
代码在这里
#include "stdio.h"
int main(void) {
printf("Hello world !\n");
return 0;
}
编译为
arm-linux-gnueabi-gcc -Wall -o crosscomp hello.c
当我在目标ARM机器上执行此crosscomp时,错误是crosscomp no such file或dir
编辑当我使用arm-linux-gnueabi-gcc时,入口点与目标机器入口点(readelf -l crosscom)不匹配但是当我用aarch64-linux-gnu编译时-gcc入口点与目标机器匹配。但现在错误在./crosscomp上被拒绝。我试着用sudo说crosscomp:没有这样的命令。
注意我在askubuntu https://askubuntu.com/questions/904685/cross-compilation-for-arm-error-no-such-file-or-directory上发布了相同的问题,但没有得到回应。
readelf的输出如下
ELF标题:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: AArch64
Version: 0x1
Entry point address: 0x400470
Start of program headers: 64 (bytes into file)
Start of section headers: 4488 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 8
Size of section headers: 64 (bytes)
Number of section headers: 29
Section header string table index: 26
答案 0 :(得分:2)
当特定可执行文件所需的动态加载程序丢失时,会发生此特殊错误消息。
通过将readelf
应用于问题可执行文件,您可以找到所需的动态加载程序的名称。在我的x86-64 Linux机器上,例如
$ readelf -l /bin/ls | grep 'program interpreter'
[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
("程序翻译"是#34;动态加载程序的另一个名称"。)
因此,在开发框上的crosscomp
二进制文件上运行上述命令。 (如果您没有readelf
或收到错误消息,请尝试arm-linux-gnueabi-readelf
。)以"程序解释程序命名的文件:"需要在目标ARM计算机上存在 。如果您不知道从哪里获取它,请发布上面命令+ ls -l
的输出,该命令应该包含丢失的文件。