cannot execute binary file: Exec format error Ubuntu 18.04 x86-64 target

I get the following error when executing my binary test1:

 $ ./test1 bash: ./test1: cannot execute binary file: Exec format error

I checked that I have the 'x' right on this binary:

 $ ls -la test1 -rwxrwxrwx 1 *** *** 5864 Apr 9 17:04 test1

I also verified that both my file and my ubuntu run on x86-64 target:

 $ file test1 test1: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped $ uname -a Linux ubuntu 5.3.0-46-generic #38~18.04.1-Ubuntu SMP Tue Mar 31 04:17:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Finally, my gcc version is:

 $ gcc --version gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

Could you help please?

2

1 Answer

The command that you used

gcc -g -Wall -c test1.c -o test1

creates a binary object file, not an executable file. From man gcc:

 When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The "overall options" allow you to stop this process at an intermediate stage. For example, the -c option says not to run the linker. Then the output consists of object files output by the assembler.

To create an executable program, you need to allow gcc to proceed to the link phase by removing the -c option:

gcc -g -Wall test1.c -o test1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like