I get the following error when executing my binary test1:
$ ./test1 bash: ./test1: cannot execute binary file: Exec format errorI checked that I have the 'x' right on this binary:
$ ls -la test1 -rwxrwxrwx 1 *** *** 5864 Apr 9 17:04 test1I 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/LinuxFinally, my gcc version is:
$ gcc --version gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0Could you help please?
21 Answer
The command that you used
gcc -g -Wall -c test1.c -o test1creates 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