Search code examples
clinuxgccx86-64file-format

linux x86_64 vm gcc error in architecture of executable output, exec file format error


I'm using GNU/Linux 64 bit Oracle VM to compile a simple c program main.c:
int main(){ return 0; }
gcc command is: gcc -c main.c -o output
When running: ./output, it results in error : "Cannot execute binary file: Exec format error"

Why the gcc compilation results an executable that doesn't correspond to the architecture of the machine(SYSV and not GNU/Linux)?
Thanks in advance


Solution

  • The -c flag tells gcc to generate an object file. Object files are not executable, instead they are input to the linker which is used to create the executable file.

    Either drop the -c flag:

    gcc main.c -o output
    

    Or build the object file and then link it:

    gcc -c main.c
    gcc main.o -o output
    

    For more information about the command-line arguments for GCC, please read the documentation for your version of GCC.