Exec格式错误32位可执行Windows子系统Linux?

For*_*892 13 executable gcc 32-bit executable-format windows-subsystem-for-linux

当我尝试执行gcc -m32 main.c -o mainWindows子系统Linux上编译的32位文件时,我收到以下错误:bash: ./main: cannot execute binary file: Exec format error.

如果我编译它没有 -m32它运行.

在WSL上运行32位可执行文件的任何解决方案?

谢谢.

Fro*_*osh 26

QEMU和binfmt支持照明方式:)

https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520

在读到WSL和Windows进程之间的WSLInterop使用了binfmt之后,我正在修改QEMU来尝试一些ARM开发,并顺便发现了如何让32位支持工作.

编辑:需要"Fall Creators Update",1709,build 16299或更新版本

安装qemu和binfmt配置:

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'
Run Code Online (Sandbox Code Playgroud)

每次启动WSL时都需要重新激活binfmt支持:

sudo service binfmt-support start
Run Code Online (Sandbox Code Playgroud)

启用i386架构包:

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386
Run Code Online (Sandbox Code Playgroud)

试试看:

$ file /usr/bin/gcc-5
/usr/bin/gcc-5: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=2637bb7cb85f8f12b40f03cd015d404930c3c790, stripped

$ /usr/bin/gcc-5 --version
gcc-5 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc helloworld.c -o helloworld

$ ./helloworld
Hello, world!

$ file helloworld
helloworld: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=3a0c7be5c6a8d45613e4ef2b7b3474df6224a5da, not stripped
Run Code Online (Sandbox Code Playgroud)

要证明它确实有效,请禁用i386支持并再试一次:

$ sudo service binfmt-support stop
 * Disabling additional executable binary formats binfmt-support [ OK ]

$ ./helloworld
-bash: ./helloworld: cannot execute binary file: Exec format error
Run Code Online (Sandbox Code Playgroud)

  • 适用于我,WIN10 1803,WSL,ubuntu 18.04 LTS linux g++-8 (2认同)

P.P*_*.P. 9

WSL尚未提供32位ELF支持.自UserVoice被提出以来似乎没有任何进展 - 你运气不好.

请参阅UserVoice:请为内核添加32位ELF支持,支持32位i386 ELF二进制文件.

如果可能,切换到真正的 Linux ;-)


phu*_*clv 9

WSL2 在使用真正Linux 内核真实虚拟机中运行,因此实际上可以执行 Linux VM 可以执行的任何操作,包括运行 32 位代码。只需通过运行安装 32 位库

sudo dpkg --add-architecture i386
sudo apt-get update
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请阅读