Run 32-bit application on Ubuntu on Windows subsystem for Linux

20,100

Solution 1

Update (WSL2)

WSL2 runs in a real virtual machine using a real Linux kernel, so it's actually possible to do anything a Linux VM can do, including running 32-bit code. Just install 32-bit libs by running

sudo dpkg --add-architecture i386
sudo apt-get update

But again, you should really opt for the 64-bit version, especially if you have the source code. 32-bit Linux is much less maintained than the 64-bit version, since there are far fewer 32-bit only hardware in the last decade along with a significantly less number of users and testers. One example is that the Meltdown/Spectre patch for 32-bit Linux came out more than half a year later than the 64-bit version, and it's still buggy for years later


Original Answer

You simply can't do that. WSL doesn't support 32-bit apps!

Most (if not all) Intel and AMD CPUs in the last decade support the x86_64 instruction set and there's no reason for Microsoft to spend time and money on supporting a 32-bit version of Linux. Most developers and Ubuntu users are running the 64-bit version anyway

No, we don’t support x86 32-bit at this time: We currently depend on x64-only instructions and mechanisms to ensure fast & stable performance.

Bash on Ubuntu on Windows


Solution 2

In addition to the answer for wsl 2, I also had to install sudo apt-get install gcc-multilib so libc6 have been installed and ELF 32bit can be executed

Share:
20,100

Related videos on Youtube

Alex
Author by

Alex

Studied programming mostly by myself reading books, forums, and trying things. The main concept: "If you don't understand what you write - don't write"

Updated on September 18, 2022

Comments

  • Alex
    Alex almost 2 years

    I have a pretty simple application that was compiled with g++ -m32 flags.

    Unfortunately, when I try to run it I am getting error:

    bash: ./a.out: cannot execute binary file: Exec format error
    

    If compiled without -m32 there is no error and it runs as expected.

    What can be a problem and is it possible to solve it?

    EDIT:

    1. Compiling with g++ -m32 --static doesn't solve the issue.
    2. Setup is Ubuntu sub-system on Windows 10.
  • MikeW
    MikeW about 5 years
    I am using WSL to build and run unit tests for an ARM platform, which is 32 bit, and hence has certain equivalences of word size between 32-bit data types and pointers, which do not exist when running in a 64-bit system. Hence this omission is annoying !
  • PaleNeutron
    PaleNeutron about 4 years
    Sry, but can you test on WSL2 if 32bit program can run. I have build a hello world program and still got the error. FIle info stack_example: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=2b667381aff3f1963c09a040c2c1f28afe3526d2, not stripped