【问题标题】:How can I fix exec format error on raspberry pi 4如何修复树莓派 4 上的 exec 格式错误
【发布时间】:2020-12-31 00:22:08
【问题描述】:

我正在尝试使用 ubuntu 服务器 20.04.1 LTS 在树莓派 4 上编译代码。我正在使用 gcc 编译它,每次我在成功编译后尝试运行文件时都会显示

-bash: ./out: cannot execute binary file: Exec format error

当我在 out 上执行文件命令时,我知道 ARM cpu 是 64 位的

out: ELF 64-bit LSB relocatable, ARM aarch64, version 1(SYSV), not stripped

这是我要运行的源代码

#include <stdio.h>
#include <stdlib.h>
int main(){
     printf("Hello World!");
     return 0;
}

这是我正在运行的 gcc 命令

gcc -march=native -ctest.c -oout

【问题讨论】:

    标签: c linux raspberry-pi4


    【解决方案1】:

    它是一个“LSB 可重定位”文件,由于尚未链接,因此无法执行,因为您的命令命令 gcc -march=native -ctest.c -oout 中的 -c 代表“仅编译和汇编,不链接”:

    $ gcc --help
    <...>
    -c                       Compile and assemble, but do not link.
    <...>
    

    你应该把所有东西都编译成可执行文件:

    gcc -march=native test.c -o out
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多