microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.26k stars 812 forks source link

I wonder if WSL will support the i386 (32 bit) program running later? #2468

Closed erikaemma closed 4 years ago

erikaemma commented 7 years ago

I just want to run arm-linux-gcc 4.4.3 :}

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

sudo apt-get install g++-multilib
sudo apt-get install libncurses5:i386
sudo apt-get install libc6:i386 libgcc1:i386 gcc-4.8-base:i386 libstdc++5:i386 libstdc++6:i386
sudo apt-get install lib32z1 lib32ncurses5 lib32ncursesw5 lib32ncursesw5-dev 
Xinmudotmoe commented 5 years ago

@Dittozzz Try using gdb-multiarch ?

d1tto commented 5 years ago

@Dittozzz Try using gdb-multiarch ?

emmmm , still like that ....

d1tto commented 5 years ago

@Dittozzz Try using gdb-multiarch ?

The arch is not compatible. Can't access memory at address 0x80484af .

lygstate commented 5 years ago

by using docker may be option, even though the wsl native docker are not stable yet, but promising

johnwcowan commented 5 years ago

It's all very well to say "vendors should update their toolchains", but some "vendors" are one-man operations who don't have the resources to add a 64-bit back end to their compilers. I'm thinking in particular of the Larceny implementation of Scheme, which is itself 32-bit-only but more to the point generates executables that are 32-bit-only. I can run these fine on actual Linux or Windows, but on WSL they don't work, which is very very annoying. (I hear they won't work on the next MacOS either.)

My current workaround is to install Larceny under Cygwin, put /mnt/c/cygwin/bin at the end of my $PATH, and make sure any code I compile is stored there too, since WSL will now run Windows executables. It's still annoying to have to type "larceny.exe" or "myprog.exe", and it's very annoying that neither one can see the WSL file system, but it's (slightly) better than nothing.

johnwcowan commented 5 years ago

It says "x32 or x64" on the Larceny home page, yes, but if you dig a little deeper you see this at <https://github.com/larcenists/larceny/blob/master/README-FIRST.txt

:

SYSTEM REQUIREMENTS Currently, this software is distributed for:

So as I said, Larceny runs in 32-bit mode and generates 32-bit mode code. If there were WSL 32-bit libraries, it would work fine. But there aren't.

On Wed, Feb 20, 2019 at 4:13 AM Markus Schaber notifications@github.com wrote:

http://www.larcenists.org/ claims that it also supports x64...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/WSL/issues/2468#issuecomment-465489675, or mute the thread https://github.com/notifications/unsubscribe-auth/ABr3hm9El8fq9F2EtkWn9nlwLKsvuOseks5vPRGlgaJpZM4PK5PH .

liudonghua123 commented 5 years ago

Based on some tinkering I was doing with qemu for some ARM dev, I think I may have found a technique to allow general 32-bit support in WSL. Hat-tip to @therealkenc for the concept 😁

Edit: requires "Fall Creators Update", 1709, build 16299 or newer (I think)

Presuming a fresh Ubuntu WSL instance, you'll need to install the qemu-user-static package, add the i386 binfmt, enable the i386 architecture, update your package lists, and install some i386 packages:

Install qemu and binfmt

sudo apt update
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'

[Edit: whoops, need to update package lists, added sudo apt update]

This will activate i386 support by causing them to be executed through qemu-i386-static, and drop a config file into /var/lib/binfmts/ for future reactivation.

You will need to reactivate this every time you restart WSL and want i386 support:

sudo service binfmt-support start

Enable i386 architecture and packages

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386

Try it out

$ 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

Proof

And to prove it really was working, 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

This works for me unless I uninstalled previous installed 64bit gcc.

johnwcowan commented 5 years ago

Awesomesauce! Thanks so much.

On Wed, Apr 3, 2019 at 2:26 AM liudonghua notifications@github.com wrote:

Based on some tinkering I was doing with qemu for some ARM dev, I think I may have found a technique to allow general 32-bit support in WSL. Hat-tip to @therealkenc https://github.com/therealkenc for the concept 😁

Edit: requires "Fall Creators Update", 1709, build 16299 or newer (I think)

Presuming a fresh Ubuntu WSL instance, you'll need to install the qemu-user-static package, add the i386 binfmt, enable the i386 architecture, update your package lists, and install some i386 packages: Install qemu and binfmt

sudo apt update

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'

[Edit: whoops, need to update package lists, added sudo apt update]

This will activate i386 support by causing them to be executed through qemu-i386-static, and drop a config file into /var/lib/binfmts/ for future reactivation. You will need to reactivate this every time you restart WSL and want i386 support:

sudo service binfmt-support start Enable i386 architecture and packages

sudo dpkg --add-architecture i386

sudo apt update

sudo apt install gcc:i386

Try it out

$ 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

Proof

And to prove it really was working, 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

This works for me unless I uninstalled previous installed 64bit gcc.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/WSL/issues/2468#issuecomment-479357058, or mute the thread https://github.com/notifications/unsubscribe-auth/ABr3hhJ0F972j7KR33n7DB_GUFmHRVrMks5vdEmagaJpZM4PK5PH .

liyanfeng662 commented 5 years ago

Have you successful run 32 bit executable on WSL OpenSuse? How to configurate it? Would you please share the details? Thanks soooo much!

liyanfeng662 commented 5 years ago

@yanygm

~中文~

update-binfmts本质是调用了Linux内核,而binfmt_misc属于Linux内核功能。

你可以在centos上编译binfmt-support,或者使用向/proc/sys/fs/binfmt_misc/register写入数据获得与update-binfmts相似的功能。

$ mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc 
 # 如果上一行执行后显示错误信息为already mounted,别管就行了。
$ echo :i386:M::'\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00':'\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff':/usr/bin/qemu-i386-static: > /proc/sys/fs/binfmt_misc/register
 # 按照:name:type:offset:magic:mask:interpreter:flags的格式写入到/proc/sys/fs/binfmt_misc/register即可完成增加你想增加的binfmt_misc功能
$ echo 1 > /proc/sys/fs/binfmt_misc/status
 # 开启binfmt_misc功能(无论是否开启)
 # 现在 尝试运行32位程序应该没什么问题了

~English translation~

The essence of update-binfmts is to call the Linux kernel, and binfmt_misc is a Linux kernel feature.

You can compile binfmt-support on centos, or use the ability to write data to /proc/sys/fs/binfmt_misc/register to get similar functionality to update-binfmts.

$ mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc 
 # If the error message is displayed as always `mounted after` the previous line is executed, ignore it.
$ echo :i386:M::'\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00':'\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff':/usr/bin/qemu-i386-static: > /proc/sys/fs/binfmt_misc/register
 # Write to /proc/sys/fs/binfmt_misc/register in the format:name:type:offset:magic:mask:interpreter:flags to increase the binfmt_misc feature you want to add.
$ echo 1 > /proc/sys/fs/binfmt_misc/status
 # Turn on the binfmt_misc function (whether or not it is enabled)
 # Now it’s okay to try to run a 32-Bit elf program.

image

Reference: Kernel Support for miscellaneous (your favourite) Binary Formats v1.1 — The Linux Kernel documentation Reference: #2468 (comment)

Have you successful run 32 bit executable on WSL OpenSuse? How to configurate it? Would you please share the details? Thanks soooo much!

liyanfeng662 commented 5 years ago

Based on some tinkering I was doing with qemu for some ARM dev, I think I may have found a technique to allow general 32-bit support in WSL. Hat-tip to @therealkenc for the concept 😁 Edit: requires "Fall Creators Update", 1709, build 16299 or newer (I think) Presuming a fresh Ubuntu WSL instance, you'll need to install the qemu-user-static package, add the i386 binfmt, enable the i386 architecture, update your package lists, and install some i386 packages:

Install qemu and binfmt

sudo apt update
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'

[Edit: whoops, need to update package lists, added sudo apt update] This will activate i386 support by causing them to be executed through qemu-i386-static, and drop a config file into /var/lib/binfmts/ for future reactivation.

You will need to reactivate this every time you restart WSL and want i386 support:

sudo service binfmt-support start

Enable i386 architecture and packages

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386

Try it out

$ 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

Proof

And to prove it really was working, 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

This works for me unless I uninstalled previous installed 64bit gcc.

Have you successful run 32 bit executable on WSL OpenSuse? How to configurate it? Would you please share the details? Thanks soooo much!

liudonghua123 commented 5 years ago

waiting for wsl2

drolevar commented 5 years ago

With WSL2 and Ubuntu 18.04 everything works out of the box. I only had to run:

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

And voila, I could install openjdk-8 in i386:

$ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b03-0ubuntu1.18.04.1-b03)
OpenJDK Server VM (build 25.212-b03, mixed mode)
$ cat `which java` | file -
/dev/stdin: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 3.2.0, BuildID[sha1]=dc5b583579ce5a9e4c34c16d692c1328c645cbb7, stripped
jerrodrs commented 5 years ago

Using WSL2 and Ubuntu 18.04 I still get "cannot execute binary file: Exec format error".

Are 32 bit binaries supported in WSL2?

PeterFeicht commented 5 years ago

@jerrodrs did you enable the architecture like @drolevar said?

sudo dpkg --add-architecture i386
sudo apt-get update
jerrodrs commented 5 years ago

@jerrodrs did you enable the architecture like @drolevar said?

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

My mistake, hadn't realized the version failed to set to 2 on my old distro. Now diagnosing that issue. #4103

PaleNeutron commented 4 years ago

WSL2, debian 10 distro, still can not run 32 bit. QQ截图20200419103227

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
onomatopellan commented 4 years ago

@PaleNeutron What does uname -a show?

PaleNeutron commented 4 years ago

@PaleNeutron What does uname -a show?

@onomatopellan

john@pn-i7z97:~$ uname -a
Linux pn-i7z97 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019 x86_64 GNU/Linux
onomatopellan commented 4 years ago

@PaleNeutron That's not a WSL2 distro. You are on build 18362 and for WSL2 you need at least build 19041.

PaleNeutron commented 4 years ago

@onomatopellan, my mistake, my windows version is 18363. Unbelievable, the stable brunch version still not update to 18917 .

onomatopellan commented 4 years ago

@PaleNeutron build 19041 is already in Release Preview Ring. That means in 2 weeks should be released as Windows 10 2004 in the stable channel.

jiucenglou commented 3 years ago

Installing cpp-5:i386 and binutils:i386 harder eventually got me there. Pretty "normal" disarray for apt though. Could be just me.

Could you suggest your detailed install procedure ? On WSL1 Ubuntu 18.04, I cannot install either cpp-5:i386 or binutils:i386, with the following complaint...

E: Sub-process /usr/bin/dpkg returned an error code (1)
ZHANGHSING commented 3 years ago

Based on some tinkering I was doing with qemu for some ARM dev, I think I may have found a technique to allow general 32-bit support in WSL. Hat-tip to @therealkenc for the concept 😁

Edit: requires "Fall Creators Update", 1709, build 16299 or newer (I think)

Presuming a fresh Ubuntu WSL instance, you'll need to install the qemu-user-static package, add the i386 binfmt, enable the i386 architecture, update your package lists, and install some i386 packages:

Install qemu and binfmt

sudo apt update
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'

[Edit: whoops, need to update package lists, added sudo apt update]

This will activate i386 support by causing them to be executed through qemu-i386-static, and drop a config file into /var/lib/binfmts/ for future reactivation.

You will need to reactivate this every time you restart WSL and want i386 support:

sudo service binfmt-support start

Enable i386 architecture and packages

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386

Try it out

$ 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

Proof

And to prove it really was working, 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

update-binfmts: warning: unable to close /proc/sys/fs/binfmt_misc/register: Invalid argument update-binfmts: exiting due to previous errors

this error due to ???

RuiWang6188 commented 3 years ago

Based on some tinkering I was doing with qemu for some ARM dev, I think I may have found a technique to allow general 32-bit support in WSL. Hat-tip to @therealkenc for the concept 😁

Edit: requires "Fall Creators Update", 1709, build 16299 or newer (I think)

Presuming a fresh Ubuntu WSL instance, you'll need to install the qemu-user-static package, add the i386 binfmt, enable the i386 architecture, update your package lists, and install some i386 packages:

Install qemu and binfmt

sudo apt update
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'

[Edit: whoops, need to update package lists, added sudo apt update]

This will activate i386 support by causing them to be executed through qemu-i386-static, and drop a config file into /var/lib/binfmts/ for future reactivation.

You will need to reactivate this every time you restart WSL and want i386 support:

sudo service binfmt-support start

Enable i386 architecture and packages

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386

Try it out

$ 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

Proof

And to prove it really was working, 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

Thanks a lot! After using this, i can run it in wsl. But can u debug it using gdb? I tried but it seems that breakpoints cannot be inserted, and it says "warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64"...... what can I do

liudonghua123 commented 3 years ago

Based on some tinkering I was doing with qemu for some ARM dev, I think I may have found a technique to allow general 32-bit support in WSL. Hat-tip to @therealkenc for the concept 😁 Edit: requires "Fall Creators Update", 1709, build 16299 or newer (I think) Presuming a fresh Ubuntu WSL instance, you'll need to install the qemu-user-static package, add the i386 binfmt, enable the i386 architecture, update your package lists, and install some i386 packages:

Install qemu and binfmt

sudo apt update
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'

[Edit: whoops, need to update package lists, added sudo apt update] This will activate i386 support by causing them to be executed through qemu-i386-static, and drop a config file into /var/lib/binfmts/ for future reactivation.

You will need to reactivate this every time you restart WSL and want i386 support:

sudo service binfmt-support start

Enable i386 architecture and packages

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386

Try it out

$ 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

Proof

And to prove it really was working, 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

Thanks a lot! After using this, i can run it in wsl. But can u debug it using gdb? I tried but it seems that breakpoints cannot be inserted, and it says "warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64"...... what can I do

I followed the above steps. But I could not install gcc:i386. I have installed gcc/g++ 9 and 10 previously. And the ubuntu I used is 20.04.

liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 10.2.0-5ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-WJNXnb/gcc-10-10.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-WJNXnb/gcc-10-10.2.0/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (Ubuntu 10.2.0-5ubuntu1~20.04)
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ ll /usr/bin/gcc*
lrwxrwxrwx 1 root root 21 Mar 30 13:55 /usr/bin/gcc -> /etc/alternatives/gcc*
lrwxrwxrwx 1 root root 23 Aug  8  2020 /usr/bin/gcc-10 -> x86_64-linux-gnu-gcc-10*
lrwxrwxrwx 1 root root 22 Aug  8  2020 /usr/bin/gcc-9 -> x86_64-linux-gnu-gcc-9*
lrwxrwxrwx 1 root root 24 Mar 30 13:55 /usr/bin/gcc-ar -> /etc/alternatives/gcc-ar*
lrwxrwxrwx 1 root root 26 Aug  8  2020 /usr/bin/gcc-ar-10 -> x86_64-linux-gnu-gcc-ar-10*
lrwxrwxrwx 1 root root 25 Aug  8  2020 /usr/bin/gcc-ar-9 -> x86_64-linux-gnu-gcc-ar-9*
lrwxrwxrwx 1 root root 24 Mar 30 13:55 /usr/bin/gcc-nm -> /etc/alternatives/gcc-nm*
lrwxrwxrwx 1 root root 26 Aug  8  2020 /usr/bin/gcc-nm-10 -> x86_64-linux-gnu-gcc-nm-10*
lrwxrwxrwx 1 root root 25 Aug  8  2020 /usr/bin/gcc-nm-9 -> x86_64-linux-gnu-gcc-nm-9*
lrwxrwxrwx 1 root root 28 Mar 30 13:55 /usr/bin/gcc-ranlib -> /etc/alternatives/gcc-ranlib*
lrwxrwxrwx 1 root root 30 Aug  8  2020 /usr/bin/gcc-ranlib-10 -> x86_64-linux-gnu-gcc-ranlib-10*
lrwxrwxrwx 1 root root 29 Aug  8  2020 /usr/bin/gcc-ranlib-9 -> x86_64-linux-gnu-gcc-ranlib-9*
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo dpkg --print-architecture
amd64
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo dpkg --print-foreign-architectures
i386
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install gcc:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc:i386 : Depends: cpp:i386 (= 4:9.3.0-1ubuntu2) but it is not going to be installed
            Depends: gcc-9:i386 (>= 9.3.0-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install gcc-10:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-10:i386 : Depends: binutils:i386 (>= 2.34) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install gcc-9:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-9:i386 : Depends: cpp-9:i386 (= 9.3.0-17ubuntu1~20.04) but it is not going to be installed
              Depends: binutils:i386 (>= 2.34) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
RuiWang6188 commented 3 years ago

Based on some tinkering I was doing with qemu for some ARM dev, I think I may have found a technique to allow general 32-bit support in WSL. Hat-tip to @therealkenc for the concept 😁 Edit: requires "Fall Creators Update", 1709, build 16299 or newer (I think) Presuming a fresh Ubuntu WSL instance, you'll need to install the qemu-user-static package, add the i386 binfmt, enable the i386 architecture, update your package lists, and install some i386 packages:

Install qemu and binfmt

sudo apt update
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'

[Edit: whoops, need to update package lists, added sudo apt update] This will activate i386 support by causing them to be executed through qemu-i386-static, and drop a config file into /var/lib/binfmts/ for future reactivation.

You will need to reactivate this every time you restart WSL and want i386 support:

sudo service binfmt-support start

Enable i386 architecture and packages

sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386

Try it out

$ 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

Proof

And to prove it really was working, 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

Thanks a lot! After using this, i can run it in wsl. But can u debug it using gdb? I tried but it seems that breakpoints cannot be inserted, and it says "warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64"...... what can I do

I followed the above steps. But I could not install gcc:i386. I have installed gcc/g++ 9 and 10 previously. And the ubuntu I used is 20.04.

liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 10.2.0-5ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-WJNXnb/gcc-10-10.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-WJNXnb/gcc-10-10.2.0/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (Ubuntu 10.2.0-5ubuntu1~20.04)
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ ll /usr/bin/gcc*
lrwxrwxrwx 1 root root 21 Mar 30 13:55 /usr/bin/gcc -> /etc/alternatives/gcc*
lrwxrwxrwx 1 root root 23 Aug  8  2020 /usr/bin/gcc-10 -> x86_64-linux-gnu-gcc-10*
lrwxrwxrwx 1 root root 22 Aug  8  2020 /usr/bin/gcc-9 -> x86_64-linux-gnu-gcc-9*
lrwxrwxrwx 1 root root 24 Mar 30 13:55 /usr/bin/gcc-ar -> /etc/alternatives/gcc-ar*
lrwxrwxrwx 1 root root 26 Aug  8  2020 /usr/bin/gcc-ar-10 -> x86_64-linux-gnu-gcc-ar-10*
lrwxrwxrwx 1 root root 25 Aug  8  2020 /usr/bin/gcc-ar-9 -> x86_64-linux-gnu-gcc-ar-9*
lrwxrwxrwx 1 root root 24 Mar 30 13:55 /usr/bin/gcc-nm -> /etc/alternatives/gcc-nm*
lrwxrwxrwx 1 root root 26 Aug  8  2020 /usr/bin/gcc-nm-10 -> x86_64-linux-gnu-gcc-nm-10*
lrwxrwxrwx 1 root root 25 Aug  8  2020 /usr/bin/gcc-nm-9 -> x86_64-linux-gnu-gcc-nm-9*
lrwxrwxrwx 1 root root 28 Mar 30 13:55 /usr/bin/gcc-ranlib -> /etc/alternatives/gcc-ranlib*
lrwxrwxrwx 1 root root 30 Aug  8  2020 /usr/bin/gcc-ranlib-10 -> x86_64-linux-gnu-gcc-ranlib-10*
lrwxrwxrwx 1 root root 29 Aug  8  2020 /usr/bin/gcc-ranlib-9 -> x86_64-linux-gnu-gcc-ranlib-9*
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo dpkg --print-architecture
amd64
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo dpkg --print-foreign-architectures
i386
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install gcc:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc:i386 : Depends: cpp:i386 (= 4:9.3.0-1ubuntu2) but it is not going to be installed
            Depends: gcc-9:i386 (>= 9.3.0-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install gcc-10:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-10:i386 : Depends: binutils:i386 (>= 2.34) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install gcc-9:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 gcc-9:i386 : Depends: cpp-9:i386 (= 9.3.0-17ubuntu1~20.04) but it is not going to be installed
              Depends: binutils:i386 (>= 2.34) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$

Actually I didn't install gcc:i386, I just run the following commands in bash of wsl

$sudo dpkg --add-architecture i386
$sudo apt update
$sudo apt install -y libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386 zlib1g-dev:i386

$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'
$sudo service binfmt-support start

Hope this will help!

liudonghua123 commented 3 years ago

When I execute sudo apt install -y libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386 zlib1g-dev:i386, I got the following errors. It seems I could not make it work.

liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install -y libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386 zlib1g-dev:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  bridge-utils dns-root-data dnsmasq-base libidn11 ubuntu-fan
Use 'sudo apt autoremove' to remove them.
Unpacking libc6-dev:i386 (2.31-0ubuntu9.2) ...
Selecting previously unselected package libgpm2:i386.
Preparing to unpack .../07-libgpm2_1.20.7-5_i386.deb ...
Unpacking libgpm2:i386 (1.20.7-5) ...
Selecting previously unselected package libtinfo5:i386.
Preparing to unpack .../08-libtinfo5_6.2-0ubuntu2_i386.deb ...
Unpacking libtinfo5:i386 (6.2-0ubuntu2) ...
Selecting previously unselected package libncurses5:i386.
Preparing to unpack .../09-libncurses5_6.2-0ubuntu2_i386.deb ...
Unpacking libncurses5:i386 (6.2-0ubuntu2) ...
Selecting previously unselected package zlib1g-dev:i386.
Preparing to unpack .../10-zlib1g-dev_1%3a1.2.11.dfsg-2ubuntu1.2_i386.deb ...
Unpacking zlib1g-dev:i386 (1:1.2.11.dfsg-2ubuntu1.2) ...
Setting up libgpm2:i386 (1.20.7-5) ...
Setting up libunistring2:i386 (0.9.10-2) ...
Setting up linux-libc-dev:amd64 (5.4.0-70.78) ...
Setting up linux-libc-dev:i386 (5.4.0-70.78) ...
Setting up libidn2-0:i386 (2.2.0-2) ...
Setting up zlib1g-dev:amd64 (1:1.2.11.dfsg-2ubuntu1.2) ...
Setting up libcrypt-dev:i386 (1:4.4.10-10ubuntu4) ...
Setting up libc6-dev:i386 (2.31-0ubuntu9.2) ...
Setting up libtinfo5:i386 (6.2-0ubuntu2) ...
Setting up libstdc++6:i386 (10.2.0-5ubuntu1~20.04) ...
Setting up libncurses5:i386 (6.2-0ubuntu2) ...
Setting up zlib1g-dev:i386 (1:1.2.11.dfsg-2ubuntu1.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...
E: Could not configure 'libc6:i386'.
E: Could not perform immediate configuration on 'libgcc-s1:i386'. Please see man 5 apt.conf under APT::Immediate-Configure for details. (2)
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install -y libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386 zlib1g-dev:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
libncurses5:i386 is already the newest version (6.2-0ubuntu2).
libc6:i386 is already the newest version (2.31-0ubuntu9.2).
libstdc++6:i386 is already the newest version (10.2.0-5ubuntu1~20.04).
zlib1g:i386 is already the newest version (1:1.2.11.dfsg-2ubuntu1.2).
zlib1g-dev:i386 is already the newest version (1:1.2.11.dfsg-2ubuntu1.2).
The following packages were automatically installed and are no longer required:
  bridge-utils dns-root-data dnsmasq-base libidn11 ubuntu-fan
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 250 not upgraded.
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo apt install qemu-user-static
Reading package lists... Done
Building dependency tree
Reading state information... Done
qemu-user-static is already the newest version (1:4.2-3ubuntu6.14).
The following packages were automatically installed and are no longer required:
  bridge-utils dns-root-data dnsmasq-base libidn11 ubuntu-fan
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 250 not upgraded.
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ 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'
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ sudo service binfmt-support start
 * Enabling additional executable binary formats binfmt-support                                                                                                 [ OK ]
liudonghua@desktop-ldh:/mnt/c/Users/Liu.D.H$ cd /tmp/
liudonghua@desktop-ldh:/tmp$
liudonghua@desktop-ldh:/tmp/hello$ cat > hello.c
#include <stdio.h>

int main() {
  printf("hello\n");
  return 0;
}
liudonghua@desktop-ldh:/tmp/hello$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 10.2.0-5ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-10 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-10-WJNXnb/gcc-10-10.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-WJNXnb/gcc-10-10.2.0/debian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (Ubuntu 10.2.0-5ubuntu1~20.04)
liudonghua@desktop-ldh:/tmp/hello$ gcc hello.c -o hello
liudonghua@desktop-ldh:/tmp/hello$ file hello
hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=006d1d9833e3d2561b61ff2afbff854d80c9af81, for GNU/Linux 3.2.0, not stripped
liudonghua@desktop-ldh:/tmp/hello$ sudo apt-get install gcc-multilib g++-multilib
Reading package lists... Done
Building dependency tree
Reading state information... Done
g++-multilib is already the newest version (4:9.3.0-1ubuntu2).
gcc-multilib is already the newest version (4:9.3.0-1ubuntu2).
gcc-multilib set to manually installed.
The following packages were automatically installed and are no longer required:
  bridge-utils dns-root-data dnsmasq-base libidn11 ubuntu-fan
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 250 not upgraded.
liudonghua@desktop-ldh:/tmp/hello$ gcc -m32 hello.c -o hello_32
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/10/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/10/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status
liudonghua@desktop-ldh:/tmp/hello$
muteryx commented 2 years ago

I just want to run arm-linux-gcc 4.5.3,but:

-bash: ./arm-arago-linux-gnueabi-gcc: No such file or directory。

The arm-arago-linux-gnueabi-gcc is existed,So,what's the problem? The version: Linux DESKTOP-DI54F8S 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux