简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM