简体   繁体   中英

./abc.o: cannot execute binary file: Exec format error

I have a Linux Virtual Machine . There are some information.

uname -a : Linux 05d57a817610 4.4.0-131-generic #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

cat /proc/version : Linux version 4.4.0-131-generic (buildd@lgw01-amd64-015) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) ) #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018

cat /etc/issue : Ubuntu 18.04.2 LTS \\n \\l

/*abc.c*/
#include<stdio.h>
int main(){

    printf("Hello World\n");
    return 0;
}

I used the command gcc abc.c -o abc.o , then I got a file: abc.o . It was executable.

When I used the command: gcc abc.c -c , it produced a file abc.o . Then I tried to use the command: ./abc.o , but it showed that bash: ./abc.o: Permission denied . With that , I used the command chmod +x abc.o , then I used the command ./abc.o , it showed that ./abc.o: cannot execute binary file: Exec format error . I have been troubled by this problem for a long time, I didn't know why. Can anyone help me? Thanks in advance.Sorry for my poor English.

There are some information you may want to know when you solve the problem.

file abc.o : abc.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

uname -m : x86_64

If you want to know any information, please leave a message in the comment. Thanks you very much.

gcc -c produces an object file, not an executable file. To create an executable file, you need to link the object file:

gcc abc.c -c
gcc abc.o -o abc

As a short-cut, you can compile a source file into a temporary object file and link that object file into an executable with a single command as well:

gcc abc.c -o abc

gcc is used for both compiling and linking (it's a front-end tool that invokes the compiler or the linker as needed.)

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