- bash: ./program: cannot execute binary file: Exec format error
- 9 Answers 9
- Решение проблемы с ошибкой «bash: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла»
- О разрядности дистрибутивов Linux и о программ
- Запуск ARM файлов в Linux
- Заключение
- Связанные статьи:
- Solved «cannot execute binary file: Exec format error»
- Solved «cannot execute binary file: Exec format error»
- 1 thought on “Solved «cannot execute binary file: Exec format error»”
bash: ./program: cannot execute binary file: Exec format error
How can I fix this? I’m using Ubuntu 14.04.2 (amd64) with VMware. I also tried using Ubuntu i386, but the result was the same.
It’s an ARM executable, i.e. you downloaded the wrong executable format or compiled for the wrong platform. You have to get the right executable or recompile.
9 Answers 9
You’re trying to run an executable compiled for an ARM architecture on an x86-64 architecture, which is much like asking your processor who only speaks English to take directions in Chinese.
If you need to run that executable you have two choices:
- Get an x86-64 version of the executable (by any mean; if you’re unable to get an x86-64 version of the executable but you’re able to get its source code, you can try to recompile it on the virtual machine);
- Install Ubuntu Server for ARM in place of Ubuntu 14.04.2 (amd64). This requires either a physical machine running on an ARM architecture or a virtualization software that can emulate it.
While the answer seems to be full-fledge, I tried to speak to my processor in English, but it arrogantly ignores me and doesn’t reply anything 🙁
This can also occur if you attempt to run an x86-64 executable on a 32-bit platform.
In one specific instance, I downloaded Visual Studio Code and tried to run it on my Ubuntu installation, but I hadn’t realized that I had installed 32-bit Ubuntu in this VM. I got this error, but after downloading the 32-bit version, it ran without issue.
It is often possible to run an ARM executable image on an amd64 system if you install the binfmt-support , qemu , and qemu-user-static packages:
sudo apt install binfmt-support qemu qemu-user-static
qemu will then perform syscall emulation when you run the executable. This works for most ARM binaries but there are a few that may not run correctly.
After install, was able to execute with /usr/bin/arm-linux-gnueabi-gcc -mfpu=neon -mcpu=cortex-a9 -mfloat-abi=softfp main.c -static
Such error may occur if all of the following are true:
- Executable is not a file but a link
- You run run it inside VM
- File is located in shared folder
- Your host is Windows.
If you got that file, let’s say, in archive — try to unpack it inside VM, in some directory inside virtual drive, not folder mapped to your host machine hard drive, for example /myNewDir/
That’s pretty helpful. For me, I created a shortcut (link) to that executable file, then executing the shortcut gave me the error.
If more than one java is installed on the system this might happen and not set as default. On Ubuntu14.04 LTS I could get it resolved by executing following and choosing the java I needed.
sudo update-alternatives --config java [sudo] password for user: update-alternatives: warning: /etc/alternatives/java has been changed (manually or by a script); switching to manual updates only There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1069 manual mode Press enter to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
I choose 2 and set openjdk-8 as a default. Which did not show the Exec format error .
Решение проблемы с ошибкой «bash: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла»
В операционной системе Linux при запуске скаченного файла, либо при запуске самостоятельно скомпилированного файла вы можете столкнуться с ошибкой:
bash: /путь/до/файла: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла
Если у вас англоязычная локаль, то ошибка будет примерно такой:
bash: ./program: cannot execute binary file: Exec format error
В самой ошибке вместо /путь/до/файла и ./program будет указан путь до файла программы, который вы хотите запустить.
Причинами данной ошибки могут быть:
- попытка запустить 64-битный файл на 32-битной системе
- файл скомпилирован для другой архитектуры (например, для ARM, а вы пытаетесь запустить его на ПК)
- вы пытаетесь выполнить не исполнимый файл, а ссылку
- файл размещён в совместной (shared) папке
Чтобы получить информацию о файле, который вы пытаетесь запустить, можно использовать утилиту file, после которой укажите путь до файла:
program: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=03ada11d91d298913990bfc074ccc3a380d26b69, with debug_info, not stripped
Здесь мы видим, что файл предназначен для 64-битной системы, об этом говорит запись 64-bit, для процессора с архитектурой x86-64.
program: ELF-32-bit LSB executable, ARM, EABI4 version 1 (SYSV), dynamically linked(uses share libs), for GNU/LINUX 2.6.16, not stripped
Этот файл для 32-битных систем, для процессора с архитектурой ARM EABI4.
Если вы не знаете, какой битности ваша система, то выполните команду:
Для 64-битных систем будет выведено x86_64, а для 32-битных – x86.
О разрядности дистрибутивов Linux и о программ
На компьютер с 32-битным процессором вы можете установить только 32-битную операционную систему и в ней запускать только 32-битные программы.
На компьютер с 64-битным процессором вы можете установить как 64-битную ОС, так и 32-битный Linux. В случае, если вы установили 64-битный дистрибутив Linux, то в нём вы можете запускать и 64-битные программы и 32-битные. А если вы установили 32-битный дистрибутив, то в нём возможно запускать только 32-битные программы.
Итак, если у вас 32-битная система, а файл для 64-битной системы или даже для ARM архитектуры, то у вас следующие варианты:
- скачать файл подходящей для вас битности и архитектуры
- если вы самостоятельно компилировали файл из исходного кода, то заново скомпилируйте для процессора вашей архитектуры
Запуск ARM файлов в Linux
Часто можно запустить исполнимые образы ARM на amd64 системах если установить пакеты binfmt-support, qemu, и qemu-user-static:
sudo apt install binfmt-support qemu qemu-user-static
Заключение
Итак, ошибка формата выполняемого файла с невозможностью запустить бинарный файл возникает из-за несоответствия программы операционной системе или архитектуре процессора. Эта проблема не должна возникать, если вы установили программу из исходных репозиториев (кроме случаев неправильной настройки источников репозитория). При возникновении этой проблемы поищите файл, подходящий для вашей архитектуры или скомпилируйте файл из исходных кодов под архитектуру вашей операционной системы.
Связанные статьи:
Solved «cannot execute binary file: Exec format error»
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»
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.
1 thought on “Solved «cannot execute binary file: Exec format error»”
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? Reply