Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
971 views
in Technique[技术] by (71.8m points)

windows subsystem for linux - Does WSL 2 really support 32 bit program?

I have googled this problem, some answers declared that WSL 2 now supports ELF 32 program.

However, a simple test on wsl2 Debian/Ubuntu distro was not passed.

Here is my test:

// install run-time
sudo dpkg --add-architecture i386
sudo apt-get update
// install build tools
sudo apt install build-essential
sudo apt install gcc-multilib
// build
gcc helloworld.c  -m32
// run!
./a.out
bash: ./a.out: cannot execute binary file: Exec format error

refers:

https://stackoverflow.com/questions/42120938/exec-format-error-32-bit-executable-windows-subsystem-for-linux
https://superuser.com/questions/1407730/run-32-bit-application-on-ubuntu-on-windows-subsystem-for-linux/1407818#1407818
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you run the command uname -a in WSL you should get a result that contains the version of your WSL. This should be something like Linux COMPUTER_NAME 4.4.0-18362-Microsoft .... the number 18362 in that output is your WSL version and it needs to be at least 19041 to be a WSL2 build (only WSL2 supports 32-bit apps).

You could also run wsl --list --verbose in a CMD shell and you will see the version of your WSL instance is 1.

WSL2 will be part of the Windows update later this month

WSL2 will be released as part of Windows 10 2004 on May 12, 2020. If you don't want to wait you can sign up for the preview builds through the "Windows Insider Program".

Get WSL2 through Windows Insider Program now (about 1 hour of work):

  • In Windows go to Settings -> Windows Insider Program and register for the program. Then go check for updates. It will take a while to download, then follow the prompts to do all the restarts, etc required.

  • Ensure "Virtual Machine Platform" is enabled in Turn Windows Features On or Off

  • In CMD or powershell run wsl --set-default-version 2 to make all future WSL installs use WSL2
  • run wsl --set-version <Distro> 2 to change an already installed instance to WSL2
    • This will take a LONG time. I gave up after reading online that it could take hours. Instead I uninstalled Ubuntu and reinstalled it. That took about 10 minutes. As long as you set the default to WSL2, the re-install will be WSL2.
  • You can verify your WSL is now version 2 by running wsl --list --verbose
  • Your 32-bit binaries should now work

I just did all of this over the last hour, because I needed to run a Zephyr simulation binary I built this morning. It worked, and I am very happy :)

Sources:

Github issue - scroll to end

Install WSL2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...