我通过以下方式从头开始在Windows 10上配置我的新Ubuntu:
# apt-get update
# apt-get install build-essential
# # Am able to compile now using "g++ -Wall -o Hello-World Hello-World.cpp", the binary is working.
# # To check versions, and that both packages were indeed installed
# gcc -v
# make -v
# apt-get install g++-multilib
# # This also installs gcc-multilib as a dependency
# # Now able to compile using "g++ -m32 -Wall -o Hello-World Hello-World.cpp
# # However the binary Hello-World can't be run. Error message "bash: ./Hello-World: cannot execute binary file: Exec format error
# apt-get install lib32gcc1 lib32stdc++6
# # Those two packages are at this time already both installed and well
# dpkg --add-architecture i386
# apt-get update
# apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
# # Still getting the same error when wanting to ./Hello-World
我想我仍然错过了一个xyz:i386 library
,我自己无法弄明白哪一个仍然缺失。此外,我不确定这是否是“Windows上的Ubuntu”特定的东西,或者如果在普通的Ubuntu 64位操作系统上以同样的方式进行此操作也会发生这种情况。你有什么建议吗?
完成后,这是Hello-World.cpp
文件的内容:
#include <iostream>
using namespace std;
int main (int argc, char **argv)
{
cout << "Hellobaby" << endl;
return 0;
}
答案 0 :(得分:1)
答案 1 :(得分:1)
在我看来,Sam Varshavchik是对的,Windows上的Ubuntu目前还不支持32位架构程序。我在VirtualBox上安装了一个虚拟的Ubuntu 64位,并且 - 使用与我的初始帖子中描述的完全相同的命令 - 程序编译并运行。
感谢大家的意见
答案 2 :(得分:0)
QEMU和binfmt支持照明方式:)
https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520
在读到WSL和Windows进程之间的WSLInterop使用了binfmt之后,我正在修补QEMU尝试一些ARM开发,并顺便发现了如何让32位支持工作。
需要&#34; Fall Creators更新&#34;,1709,构建16299或更新
安装qemu和binfmt config:
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时,您都需要重新激活binfmt支持:
sudo service binfmt-support start
启用i386架构包:
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install g++:i386
尝试一下:
$ file /usr/bin/g++-5
/usr/bin/g++-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]=9835ed3e5b1c8707591630e314ba4030a571deec, stripped
$ /usr/bin/g++-5 --version
g++-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.
$ g++ -m32 -Wall helloworld.cpp -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]=65905fae78b837162a29d618b4ce63d300c62cb6, not stripped
要证明它确实有效,请禁用i386支持并再试一次:
$ sudo service binfmt-support stop
* Disabling additional executable binary formats binfmt-support [ OK ]
$ ./helloworld
-bash: ./helloworld: cannot execute binary file: Exec format error