Debian多架构环境下安装hello:i386执行报错:cannot execute binary file: Exec format error
Debian多架构环境下安装hello:i386执行报错:cannot execute binary file: Exec format error
嘿,我完全懂你的困惑——照着官方指南一步步操作,结果程序跑不起来确实挺闹心的。咱们来捋清楚问题出在哪:
首先看你的系统信息:uname -a显示这是aarch64(arm64)架构的Debian系统,而你安装的hello:i386是针对Intel x86 32位处理器编译的二进制程序。arm64和x86属于完全不同的指令集,处理器原生根本没法直接识别x86的代码,所以直接执行才会弹出“Exec format error”。
Debian的Multiarch机制主要是解决同指令集下不同位宽的库和程序共存问题(比如amd64系统装i386程序,因为x86_64处理器原生支持32位x86代码),但跨不同指令集的架构运行程序,还得靠CPU架构模拟工具来帮忙。
解决方法很简单:
安装qemu-user-static和binfmt-support这两个工具,它们会让系统自动用QEMU来模拟x86架构,从而运行i386的二进制程序:
sudo apt update sudo apt install qemu-user-static binfmt-support
安装完成后,再试试执行hello,应该就能正常输出问候语了。
附你提供的原始操作及报错信息:
$ sudo dpkg --add-architecture i386 $ sudo dpkg --print-architecture arm64 $ sudo dpkg --print-foreign-architectures i386 $ sudo apt install hello:i386 ... Setting up hello:i386 (2.10-3) $ hello bash: /usr/bin/hello: cannot execute binary file: Exec format error $ uname -a Linux palpie 6.1.0-18-arm64 #1 SMP Debian 6.1.76-1 (2024-02-01) aarch64 GNU/Linux $ file /usr/bin/hello /usr/bin/hello: ELF 32-bit LSB pie executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, BuildID[sha1]=b603448350eaBeabcd86efb46cb3ec52d6bdec9f, for GNU/linux 3.2.0 stripped这不应该“直接工作”吗?
备注:内容来源于stack exchange,提问作者HankCa
相关产品推荐
相关产品推荐

