3
votes

I am trying to compile code on the raspberry pi 4 using ubuntu server 20.04.1 LTS. I am using gcc to compile it and every time I try and run the file after it gets compiled successfully it says

-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

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 -march=native -ctest.c -oout
1

1 Answers

5
votes

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":

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

You should compile everything into an executable:

gcc -march=native test.c -o out