一、背景
windows下用WSL運行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位的程序
安裝 qemu & 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
三、WSL開機啟動設置
1.WSL中添加文件
vim /etc/myinit.sh
sudo service binfmt-support start
2.在Windows下添加啟動文件
(1).Ctrl+R打開"運行",輸入"shell:startup",會彈出StartUp目錄
(2).創建wsl-binfmt-support.vbs文件
Set ws = WScript.CreateObject("WScript.Shell")
cmd = "C:\Windows\System32\bash.exe -c ""bash /etc/myinit.sh"""
' 運行命令不顯示cmd窗口
ws.Run cmd, 0, false
Set ws = Nothing
WScript.quit
搞定。
參考:
https://github.com/Microsoft/WSL/issues/2468
https://blog.csdn.net/fcymk2/article/details/79711566