QEMU and binfmt support make it easy :)
https://github.com/microsoft/wsl/issues/2468#issuecomment-374904520
After reading that WSLInterop used binfmt between WSL and Windows processes, I worked on QEMU to try some ARM designs and accidentally discovered how to work with 32-bit support.
Requires an update to Fall Autodesk, 1709, build 16299 or later
Install qemu and binfmt configuration:
sudo apt install qemu-user-static sudo update-binfmts
You will need to reactivate binfmt support every time you start WSL:
sudo service binfmt-support start
Enable i386 architecture packages:
sudo dpkg --add-architecture i386 sudo apt update sudo apt install g++:i386
Try:
$ 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
And to make sure it really works, disable i386 support and try again:
$ sudo service binfmt-support stop * Disabling additional executable binary formats binfmt-support [ OK ] $ ./helloworld -bash: ./helloworld: cannot execute binary file: Exec format error