Ошибка формата выполняемого файла linux

I’m trying to run a program, but it gives an error:

bash: ./program: cannot execute binary file: Exec format error

The result of file program was:

program: ELF-32-bit LSB executable, ARM, EABI4 version 1 (SYSV), dynamically linked (uses share libs), for GNU/LINUX 2.6.16, not stripped

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.

Bas van Paassen's user avatar

asked Jul 15, 2015 at 5:30

Soongeun Hwang's user avatar

Soongeun HwangSoongeun Hwang

1,5012 gold badges9 silver badges4 bronze badges

1

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:

  1. 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);

  2. 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.

answered Jul 15, 2015 at 5:39

kos's user avatar

1

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.

answered Sep 10, 2015 at 23:44

Hughie Coles's user avatar

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.

ArrayBolt3's user avatar

answered Oct 27, 2016 at 6:41

Nathan Osman's user avatar

Nathan OsmanNathan Osman

31.8k40 gold badges177 silver badges259 bronze badges

2

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/

wjandrea's user avatar

wjandrea

14k4 gold badges46 silver badges97 bronze badges

answered Nov 13, 2015 at 22:22

Pavel's user avatar

PavelPavel

3631 gold badge3 silver badges10 bronze badges

1

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.

Videonauth's user avatar

Videonauth

32.9k16 gold badges104 silver badges119 bronze badges

answered Jun 6, 2016 at 13:43

lambzee's user avatar

You must compile your file using an appropriate CPU architecture (x86 for example) and copy the .exe file on your linux machine. Then you can install mono on your linux machine and issue the following command:

mono myprogram.exe

muru's user avatar

muru

191k52 gold badges468 silver badges719 bronze badges

answered Feb 28, 2016 at 19:49

user3578181's user avatar

1

This can also happen if the binary uses a libc implementation which is not libc, such as musl. These days this specific problem is most likely encountered when trying to run a binary with libc in a Docker container with an image based on alpine. There is nothing that can be done to the binary itself to support both environments, because the libc implementation must always be linked statically, i.e. built directly into the binary, for reasons.

answered Jul 16, 2019 at 16:44

Zyl's user avatar

I got this error trying to run a zip file containing an executable rather than extracting it and running the executable itself xD

In addition to the other answers offered here, I suppose there would be a lot of file types that aren’t intended to be executable which could cause this error.

answered May 19, 2020 at 6:05

Alexander Taylor's user avatar

1

This is another special case: WSL (Windows Subsystem for Linux) by default(!) only supports 64bit executables. I think this is a rather unusual behaviour, as normally there is a backwards compatibility.

(Even more special is that selecting 64bit in a formerly 32bit project of Windev won’t fix your issue. You need to start a new project, selecting 64bit right in the beginning. Tested on Windev 26. This IDE sucks, forced to use it because of working legacy code.)

answered Jul 21, 2022 at 23:23

PythoNic's user avatar

PythoNicPythoNic

6661 gold badge5 silver badges15 bronze badges

2

Перейти к содержимому

Ситуация

При запуске программы через меню приложений возникает эта ошибка, программа не запускается.

Я встречал это на Oracle SQLDeveloper любой версии 20+, который устанавливался из официального rpm в среде Ubuntu + KDE с помощью sudo alien -dic. Ошибки не было в MATE. Может не встречаться в GNOME. Встретил только в KDE.

Ошибки нет, если запустить программу напрямую из терминала.

Ошибки нет, если запустить desktop-файл через gio launch.

Выдача прав a+x на desktop-файлы не помогает.

Запуск через kioclient5 exec прерывается ошибкой:

Неизвестная ошибка 100
execvp: Ошибка формата выполняемого файла
Отправьте сообщение об ошибке на https://bugs.kde.org

Проблема

Команда в desktop-файле:

[Desktop Entry]
...
Exec=sqldeveloper
...

Проверяем в терминале:

$ which sqldeveloper
/usr/local/bin/sqldeveloper

$ file "$(which sqldeveloper)"
/usr/local/bin/sqldeveloper: ASCII text

$ head -2 "$(which sqldeveloper)"
/opt/sqldeveloper/sqldeveloper.sh

$ cat /opt/sqldeveloper/sqldeveloper.sh
#!/bin/bash
cd "`dirname $0`"/sqldeveloper/bin && bash sqldeveloper $*

Вывод простой: штатный desktop-файл ссылается на шелл-скрипт без шибенга, который запускает шелл-скрипт с шибенгом. Проблема именно в первом.

Решение

  1. Изменить параметр Exec в desktop-файле на корректный скрипт или бинарник.
  2. Добавить шибенг в первый шелл-скрипт, тогда результат должен быть таким:
$ file "$(which sqldeveloper)"
/usr/local/bin/sqldeveloper: Bourne-Again shell script, ASCII text executable

Предполагаю, что аналогичное решение подойдёт для другого ПО. По крайней мере, стоит попробовать.

You have a 64-bit x86 CPU (indicated by the lm flag in /proc/cpuinfo), but you’re running a 32-bit kernel. The program you’re trying to run requires a 64-bit runtime, so it won’t work as-is: even on a 64-bit CPU, a 32-bit kernel can’t run 64-bit programs.

If you can find a 32-bit build of the program (or build it yourself), use that.

Alternatively, you can install a 64-bit kernel, reboot, and then install the 64-bit libraries required by your program.

To install a 64-bit kernel, run

sudo dpkg --add-architecture amd64
sudo apt-get update
sudo apt-get install linux-image-generic:amd64

This will install the latest 64-bit Xenial kernel, along with various supporting 64-bit packages. Once you reboot, you should find that uname -a shows x86_64 rather than i686. If you attempt to run your program again, it might just work, or you’ll get an error because of missing libraries; in the latter case, install the corresponding packages (use apt-file to find them) to get the program working.

Photo by Jivacore/Shutterstock.com

Linux has been reworked heavily since it first came out to the point that it’s no longer an OS for terminal kings. Just about everyone can use it now thanks to the much better user interfaces that we see in modern Linux distros. However, that doesn’t mean it can’t be frustrating at times. 

In this article, we’re taking a look at the “cannot execute binary file: exec format error” issue and giving you a few solutions on how to get rid of the problem. 

Also read: How to make a file executable in Linux?


Check the architecture

The first thing you should do is ensure you’ve got the right bin file. Binary files made for 32-bit systems won’t work on 64-bit systems and vice-versa. You can check the architecture of any file by using the command below.

file filename

How to fix Cannot execute binary file: exec format error?

If the architecture doesn’t match between your file and the PC you’re running it on, try running the corresponding binary file for the matching architecture. 


Check the file

Binary files can be run on Windows, Linux and macOS. However, binaries made for one OS won’t run on the others. Generally, these files have different file formats to help users distinguish between them. If you’re trying to run a binary file made for Windows on a Linux distro, it’s obviously not going to work. 

If you must run the binary on Linux however, we recommend downloading Wine and using it to run the file. Wine is a compatibility layer capable of running Windows applications on POSIX-compliant operating systems, including Linux and macOS. 


Install GCC and Gfortran

GCC and Gfortran are required for several binary files to compile and execute properly. You can install them by typing the command below in your terminal. 

sudo apt-get install gfortran && sudo apt-get install build-essential

How to fix Cannot execute binary file: exec format error?

Now try running your binary file again and it should run without a problem — fixing the ‘cannot execute binary file’ error.


Uncompress the file

Sometimes binary files are compressed to make them easier to share over the internet. Try uncompressing the file to see if that helps you run it fine. Run the following commands on at a time. 

xz -d ./filename
chmod +x ./filename
./filename

Check file permissions

Another potential reason for your binary file not running could be that the user doesn’t have permission to change or read the file. You can fix this by typing the following command in the terminal. 

chmod +x filename

How to fix Cannot execute binary file: exec format error?

Once the permissions are set, you can run the file by typing this.

./filename

Use Dos2unix

The Dos2unix command can sometimes help binaries made for DOS to run on UNIX systems. Try using the following command to see if your file runs or not. 

dos2unix filename.bin

If we’ve missed out on any fixes that helped you solve the ‘cannot execute binary file’ error, please comment down below with the fix.

Also read: What does ./ mean in Linux?


0

3

Сразу укажу, что я полнейший нуб. Учусь пользоваться линуксом. Сейчас стоит fedora 22. Не запускаются скомпилированные исполняемые файлы. Компилирую СИшные файлики через ком строку. «gcc -c file.c -o file.o» и «gcc file.o -o file».
После этих действий выдает ошибку при запуске через sh «не могу запустить бинарный файл.» Не хочет запускать ни file.o, ни file.
Переустанавливал bash и gcc через ком строку с помощью dnf reinstall, не помогло. Мне интересен любой способ решения этой проблемы, который я буду способен в кратчайшие сроки освоить.

Понравилась статья? Поделить с друзьями:
  • Ошибка формата валидация xsd
  • Ошибка формата lid атол активация
  • Ошибка формата lid frontol
  • Ошибка формат файла не поддерживается
  • Ошибка формат не поддерживается устройством