1. 程式人生 > >Bash On Windows(WSL)無法運行32Bit程序,報錯cannot execute binary file: Exec format error解決辦法

Bash On Windows(WSL)無法運行32Bit程序,報錯cannot execute binary file: Exec format error解決辦法

update bit sof 解決 ble bash ann code 通過

一、背景

windows下用linux工具,但32位的卻無法運行報錯

aapt: cannot execute binary file: Exec format error
file aapt
aapt: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.24

二、解決辦法

github上@Froosh給出了他的解決方案,通過安裝qemu來運行32位的程序
具體步驟:
Install qemu and binfmt

sudo apt update
sudo apt install qemu-user-static
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic ‘\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00‘ --mask ‘\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff‘

這一步實現了把程序的運行交由qemu-user-static來運行,從而實現運行32位

註意每次重啟WSL都得重新開啟,可將這步加到開機自動啟動中

sudo service binfmt-support start

參考:
https://github.com/Microsoft/WSL/issues/2468

Bash On Windows(WSL)無法運行32Bit程序,報錯cannot execute binary file: Exec format error解決辦法