- bash: ./program: невозможно выполнить двоичный файл: ошибка формата Exec
- How to Fix ‘cannot execute binary file: Exec format error’ on Ubuntu
- Method 1: Using the arch Command
- Method 2: Using the file Command
- Решение проблемы с ошибкой «bash: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла»
- О разрядности дистрибутивов Linux и о программ
- Запуск ARM файлов в Linux
- Заключение
- aarch64-linux-gnu-gcc cannot execute binary file: Exec format error #224
- Comments
- Rtlagot commented Jan 17, 2018
- jforissier commented Jan 17, 2018
- Rtlagot commented Jan 17, 2018
- jbech-linaro commented Jan 17, 2018
- jforissier commented Jan 17, 2018
- igoropaniuk commented Jan 17, 2018
- Rtlagot commented Jan 17, 2018 •
- jbech-linaro commented Jan 17, 2018
bash: ./program: невозможно выполнить двоичный файл: ошибка формата Exec
Я пытаюсь запустить программу, но ошибка происходит так:
Результатом file program было:
Как я могу исправить эту ошибку?
Я использую Ubuntu 14.04.2 (amd64) с VMware. Я тоже пробовал с Ubuntu i386, но результат был таким же.
Вы пытаетесь запустить исполняемый файл, скомпилированный для архитектуры ARM на архитектуре x86-64, что очень похоже на запрос вашего процессора, который говорит только по-английски, указывать направление на китайском.
Если вам нужно запустить этот исполняемый файл, у вас есть два варианта:
Получить версию исполняемого файла x86-64 (любым способом; если вам не удается получить версию исполняемого файла x86-64, но вы можете получить его исходный код, вы можете попытаться перекомпилировать его на виртуальной машине );
Установите Ubuntu Server for ARM вместо Ubuntu 14.04.2 (amd64). Для этого требуется либо физическая машина, работающая на архитектуре ARM, либо программное обеспечение для виртуализации, которое может эмулировать ее.
Это также может произойти, если вы попытаетесь запустить исполняемый файл x86-64 на 32-разрядной платформе.
В одном конкретном случае я скачал код Visual Studio и попытался запустить его на своей установке Ubuntu, но я не понял, что я установил 32-битную Ubuntu в эту виртуальную машину. Я получил эту ошибку, но после загрузки 32-разрядной версии, он работал без проблем.
Часто можно запустить исполняемый образ ARM в системе amd64, если вы установите пакеты binfmt-support , qemu и qemu-user-static :
qemu затем выполнит эмуляцию syscall при запуске исполняемого файла. Это работает для большинства двоичных файлов ARM, но есть некоторые, которые могут работать неправильно.
Такая ошибка может возникнуть, если выполняются все следующие условия:
- Исполняемый файл — это не файл, а ссылка
- Вы запускаете запустить его внутри ВМ
- Файл находится в общей папке
- Ваш хост — Windows.
Если вы получили этот файл, скажем, в архиве — попробуйте распаковать его внутри виртуальной машины, в какой-то каталог внутри виртуального диска, а не в папку, сопоставленную, например, с жестким диском хост-машины. /myNewDir/
Вы должны скомпилировать свой файл, используя соответствующую архитектуру ЦП (например, x86), и скопировать файл .exe на свой компьютер с Linux. Затем вы можете установить mono на вашем Linux-компьютере и выполнить следующую команду:
Если java в системе установлено более одного, это может произойти и не будет установлено по умолчанию. На Ubuntu14.04 LTS я мог решить ее, выполнив следующее и выбрав java нужное.
Я выбираю 2 и устанавливаю openjdk-8 по умолчанию. Который не показал Exec format error .
Это также может произойти, если двоичный файл использует реализацию libc, которая не является libc, например, musl. В эти дни эта конкретная проблема, скорее всего, встречается при попытке запуска двоичного файла с libc в контейнере Docker с изображением, основанным на alpine. Ничто не может быть сделано с самим двоичным файлом для поддержки обеих сред, потому что реализация libc всегда должна быть статически связана, то есть встроена непосредственно в двоичный файл, по причинам.
Источник
How to Fix ‘cannot execute binary file: Exec format error’ on Ubuntu
While it shouldn’t happen when using the official apt-get repositories, if you download software off the Internet and run it then there’s a chance that you’ll see the dreaded bash: ./nameOfProgram: cannot execute binary file: Exec format error. This error, which is usually followed by bash: ./nameOfProgram.sh: Permission denied or something like it, indicates that Ubuntu wasn’t able to interface correctly with the binary you downloaded. This is because while it’s apparently a valid Linux binary, it’s designed for a different chipset than your kernel currently supports.
Most people using Ubuntu are on 32-bit or 64-bit processors based around a standard architecture that Intel released, regardless of who actually made their microchips. It’s important to remember that 64-bit processors can run in 32-bit mode, so if you’re getting this error even though you have a 64-bit processor there’s a chance you’re running a 32-bit version of Ubuntu. A few simple commands are all it takes to tell what your chip is operating as.
Method 1: Using the arch Command
If you’re not familiar with the type of microprocessor that you have installed on your machine, then you’ll first want to use the arch command from the command line. You’ll only see a single line of output returned to you after running this command. In many cases, you’ll see i686, which means that you’re on a 32-bit processor and therefore can’t run x86_64 binaries. If you instead see amd64 or something similar, then you’re on an x86_64 processor, and should at least theoretically be able to run most 32-bit and 64-bit binaries. Unlike Microsoft Windows, Ubuntu Linux actually contains the proper tools to permit users of 644-bit chipsets to run 16-bit Windows programs in their operating system in many cases as well.
These terms are still true even if you’re not actually using that particular model of microchip. For instance, i686 is how Linux refers to many 32-bit processors even if they aren’t actually Intel 80686 chips. Even if you’re using 64-bit Intel technology, arch might still call your processor an amd64 chip. This doesn’t indicate an error, and can be safely ignored. You can use cat /proc/cpuinfo or more /proc/cpuinfo to find out the exact type of processor you’re using. Since the lines in this file are long, you might want to push F11 before issuing it if you’re using a graphical terminal window. Users of a virtual console, especially those working with Ubuntu server, won’t have to worry quite as much.
You may see some other types of output, which might further restrict your options when it comes to running software. Ubuntu supported PowerPC architecture for the longest time, which is found in some workstations as well as many Classic Macintosh and older OS X Macintosh machines. You can actually still find Ubuntu repositories for these architectures, though they receive little support today. However, you more than likely won’t be able to run many Linux binaries you download from the Internet outside of the official repositories in this case. That doesn’t mean that Ubuntu doesn’t work on these machines, though you may want to look at the lighter Lubuntu distribution.
Method 2: Using the file Command
The file command identifies what different files contain, and it’s usually very accurate. Try identifying the file in question by typing file nameOfProgram to see if you get ELF 32-bit or ELF 64-bit as output. If it tells you that it’s an ELF 64-bit binary and you received i686 as output from the arch command, then there’s no way you can reasonably run it on your machine. If you’re on a 64-bit microprocessor running 32-bit Ubuntu, then you could technically reinstall the operating system, though this is a bit of an extreme step in order to run a single program.
There is also the very real possibility, however slight, that you might instead come across a binary that when you attempt to run it spews out junk characters to the terminal even if you’ve run a malware scan on it. These characters usually take the form of either lozenge-shaped blocks, or alternatively rectangular cubes that have numerical values in them. Some computer scientists call the latter tofu, and represent the Unicode values of characters that your currently installed typefaces won’t be able to display. If the terminal is displaying them like this, then you can rest assured that this is neither a font error nor anything having to do with malware. Rather, this is simply because the compiled microprocessor opcode inside of the binary is so alien to your system that it doesn’t know how to interpret some of the code.
The best way to fix this is to install the proper package for your architecture. If you’re installing packages from inside Ubuntu, then the apt-get system or the graphical Synaptic manager has you covered without any problems. If you’re downloading packages from another distribution, then you’ll need to find the right one for your architecture. Take, for example, Arch Linux’s listing of the gvim package. While the default package features the x86_64 architecture, there’s also one for the i686 chipset. This one will work on 32-bit machines that work with the Intel interrupt structure, but remember that the terms i686 and 32-bit are not mutually inclusive all the time since other chipsets Linux supports actually do feature their own 32-bit implementations.
Users exploring the whole GNU/Linux scene might come across binaries compiled for far more exotic technologies than these. Linux is truly a cross-platform code scene, so you’ll see OpenRISC, MIPS, SPARC, M32R, MN103, ARM, ARC, Alpha and many other standards binaries are compiled to work with. More than likely, you won’t be able to run any of these, though ARM is an extremely popular tablet and smartphone platform. It’s also the platform that the Raspberry Pi is based around, which means if you’re actually running Ubuntu on a mobile device or the Ubuntu MATE distribution for Raspberry Pi you’ll actually need these instead of Intel 32-bit or x86_64 binaries.
Источник
Решение проблемы с ошибкой «bash: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла»
В операционной системе Linux при запуске скаченного файла, либо при запуске самостоятельно скомпилированного файла вы можете столкнуться с ошибкой:
Если у вас англоязычная локаль, то ошибка будет примерно такой:
В самой ошибке вместо /путь/до/файла и ./program будет указан путь до файла программы, который вы хотите запустить.
Причинами данной ошибки могут быть:
-
- попытка запустить 64-битный файл на 32-битной системе
-
- файл скомпилирован для другой архитектуры (например, для ARM, а вы пытаетесь запустить его на ПК)
-
- вы пытаетесь выполнить не исполнимый файл, а ссылку
Чтобы получить информацию о файле, который вы пытаетесь запустить, можно использовать утилиту file, после которой укажите путь до файла:
Здесь мы видим, что файл предназначен для 64-битной системы, об этом говорит запись 64-bit, для процессора с архитектурой x86-64.
Ещё один пример:
Этот файл для 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:
Заключение
Итак, ошибка формата выполняемого файла с невозможностью запустить бинарный файл возникает из-за несоответствия программы операционной системе или архитектуре процессора. Эта проблема не должна возникать, если вы установили программу из исходных репозиториев (кроме случаев неправильной настройки источников репозитория). При возникновении этой проблемы поищите файл, подходящий для вашей архитектуры или скомпилируйте файл из исходных кодов под архитектуру вашей операционной системы.
Источник
aarch64-linux-gnu-gcc cannot execute binary file: Exec format error #224
Comments
Rtlagot commented Jan 17, 2018
I’ve been trying to get the OP-TEE working on a Raspberry 3 following every instructions from the prerequisites, but i keep getting this error at the step 7.5 Build the solution. I tried different OS, 32 and 64 bits, but i keep getting this error, even if all the step before went perfectly. Here is the full log :
make -C /home/pi/devel/optee/build/../optee_os O=out/arm CFG_ARM64_core=y CROSS_COMPILE=» /home/pi/devel/optee/build/../toolchains/aarch64/bin/aarch64-linux-gnu-» CROSS_COMPILE_core=» /home/pi/devel/optee/build/../toolchains/aarch64/bin/aarch64-linux-gnu-» CROSS_COMPILE_ta_arm64=/home/pi/devel/optee/build/../toolchains/aarch64/bin/aarch64-linux-gnu- CROSS_COMPILE_ta_arm32=/home/pi/devel/optee/build/../toolchains/aarch32/bin/arm-linux-gnueabihf- CFG_TEE_CORE_LOG_LEVEL=3 DEBUG=0 CFG_TEE_BENCHMARK=n PLATFORM=rpi3
make[1]: Entering directory ‘/home/pi/devel/optee/optee_os’
CHK out/arm/conf.mk
CHK out/arm/include/generated/conf.h
/bin/bash: /home/pi/devel/optee/build/../toolchains/aarch64/bin/aarch64-linux-gnu-gcc: cannot execute binary file: Exec format error
mk/compile.mk:228: recipe for target ‘out/arm/core/include/generated/.asm-defines.s’ failed
make[1]: *** [out/arm/core/include/generated/.asm-defines.s] Error 126
make[1]: Leaving directory ‘/home/pi/devel/optee/optee_os’
common.mk:306: recipe for target ‘optee-os-common’ failed
make: *** [optee-os-common] Error 2
Any idea what i might be doing wrong ?
The text was updated successfully, but these errors were encountered:
jforissier commented Jan 17, 2018
aarch64-linux-gnu-gcc is a Linux x86_64 binary, so it will run only on a Linux machine running a 64-bit distribution for Intel-compatible CPUs.
Rtlagot commented Jan 17, 2018
I don’t really get it, this means they say it should work on Raspberry but because the processor is actually an ARM it won’t work on it ?
jbech-linaro commented Jan 17, 2018
@Fizbanoide , what does your build machine say when you are running:
And what does file say?
jforissier commented Jan 17, 2018
It is assumed that everything is built using cross-compilation. With some relatively minor changes to the build files, it should be possible to build natively, but many target platforms have limited resources such as slow CPUs, limited/slow persistent storage, no networking capabilities etc. so native build is often not an option.
igoropaniuk commented Jan 17, 2018
@jbech-linaro, based on home directory «/home/pi» in provided logs, seems that @Fizbanoide is trying to build everything on RPi3.
Rtlagot commented Jan 17, 2018 •
Thanks for your answers.
@jbech-linaro Here are the results :
aarch64-linux-gnu-gcc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=dfec1a1c34b791582e69a236ebf2f7b95df3fea0, stripped
@igoropaniuk Exactly, i’m running all this on a RPi3
jbech-linaro commented Jan 17, 2018
aarch64-linux-gnu-gcc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=dfec1a1c34b791582e69a236ebf2f7b95df3fea0, stripped
Источник