In this article, we will see how to solve cannot execute binary file: Exec format error
. Sometimes you might have noticed that when you try to run some binary file into your system then it immediately resulted into cannot execute binary file: Exec format error
. This error might be annoying sometime as you may think you are using the correct binary file in your System but still it is not working. The same thing happened with me as well.
I have downloaded the gcc tarball for Linux system from Arm official website thinking that I am downloading the correct file but after extracting the tarball when I tried to check the gcc version then I realized it was the incorrect file. At this time, I decided to write an article about this thinking that there might be lot of folks out there doing same mistake as I did either knowingly or unknowingly. So here I am going to cover all the possible reasons in detail that could result into cannot execute binary file: Exec format error
.
Solved "cannot execute binary file: Exec format error"
Also Read: How to Install KDE Plasma Desktop(GUI) on Fedora 37 Linux
As stated earlier, when I tried to check the version of gcc compiler by running ./arm-none-eabi-gcc --version
then I noticed cannot execute binary file: Exec format error
on the output as you can also see below.
cyberithub@ubuntu:~/gcc-arm-none-eabi-10.3-2021.10/bin$ ./arm-none-eabi-gcc --version -bash: ./arm-none-eabi-gcc: cannot execute binary file: Exec format error
While there could be few reasons for above error but most of the time this error occurs when you try to run different architecture binary in your System. In my case, I was trying to run Linux AArch64 GCC binary on a 64-bit architecture. This immediately resulted into cannot execute binary file: Exec format
error. To fix this error, I simply needed to download the Linux x86_64 tarball from the official website. After extracting the tarball when I again tried to run the binary then this time it ran successfully as you can see below.
cyberithub@ubuntu:~/gcc-arm-none-eabi-10.3-2021.10/bin$ ./arm-none-eabi-gcc --version arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.10) 10.3.1 20210824 (release) Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Similarly, if you try to run a x86-64 executable on a 32-bit platform then also you will get the same cannot execute binary file: Exec format error
. So you need to make sure you are downloading the right package for your system architecture. If you don't know about your current system architecture then in a linux based system, you can run uname -m
command to check that as you can see below.
cyberithub@ubuntu:~$ uname -m x86_64
Sometimes, I have also seen when users trying to run some zip file containing an executable, the same error will show on the output. For those cases, users always needs to first extract the zip file using unzip
or some other extraction utilities and then only try to run the executable. This would definitely solve the problem.
In few of the cases, I have also seen users taking the package source code and compiling it in a specific architecture and then trying to use the binary in some other architecture. This will also result into the same error as you cannot run that generated binary file in a different system architecture unless and until you have some underlying library or compiler that makes the generated binary platform independent.
Hope above solution would be enough to solve your error as well. Please do let me know in the comment box if you come across any situation which is not covered here that results into cannot execute binary file: Exec format error
so that it will help others as well.
I have created a C++ binary in amd64. I tried creating binary by changing intellisense to gccarm64. But still I am not able to execute the binary in arm64. Could you please share your thoughts on this?