在WSL中运行32位程序


今天发现在WSL中运行32位程序hmetis会报错:

-bash: ./hmetis: cannot execute binary file: Exec format error

用file hmetis命令查看文件信息:

hmetis: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.0.0, stripped

 

经过查找,发现github上@Froosh给出了他的解决方案,通过安装qemu来运行32位的程序:https://github.com/Microsoft/WSL/issues/2468

1. 首先安装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'

每次重新启动WSL并希望i386支持时,您都需要重新激活此功能:

sudo service binfmt-support start

2. 接下来启用i386体系结构和package

sudo dpkg --add-architecture i386 sudo apt update sudo apt install cpp-9:i386 sudo apt install gcc:i386

至此,就可以运行之前的32位binary了。

3. 设置开机启动

vim /etc/myinit.sh
sudo service binfmt-support start

 

参考:https://www.cnblogs.com/TatuCz/p/10330820.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM