[英]How can I fix exec format error on raspberry pi 4
I am trying to compile code on the raspberry pi 4 using ubuntu server 20.04.1 LTS.我正在尝试使用 ubuntu 服务器 20.04.1 LTS 在 raspberry pi 4 上编译代码。 I am using gcc to compile it and every time I try and run the file after it gets compiled successfully it says
我正在使用 gcc 来编译它,每次我在成功编译后尝试运行文件时,它都会说
-bash: ./out: cannot execute binary file: Exec format error
When I do the file command on out I get, and I know that the ARM cpu is 64bit当我执行 file 命令时,我知道 ARM cpu 是 64 位
out: ELF 64-bit LSB relocatable, ARM aarch64, version 1(SYSV), not stripped
This is the source that I am trying to run这是我试图运行的源
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("Hello World!");
return 0;
}
This is the gcc command I am running这是我正在运行的 gcc 命令
gcc -march=native -ctest.c -oout
It's a "LSB relocatable" file, which is not executable since it hasn't been linked because the -c
in your command command gcc -march=native -ctest.c -oout
stands for "compile and assemble only, do not link":这是一个“LSB重定位”的文件,因为它一直没有联系是不可执行的,因为
-c
在command命令gcc -march=native -ctest.c -oout
代表“编译,只有组装,不链接” :
$ gcc --help
<...>
-c Compile and assemble, but do not link.
<...>
You should compile everything into an executable:您应该将所有内容编译为可执行文件:
gcc -march=native test.c -o out
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.