3

I am trying to use Ubuntu WSL to build the GNU GCC 9.3.0 toolchain, and thought I managed to do do this, but then I couldn't actually use it as a kit in VSCode. I then assumed I did something wrong, and tried to delete the git repo, and the result from compiling, and do it again.

I have already downloaded all dependencies (I think), so that it fully ran everything without saying it encountered an error. But if you are knowledgeable about the compilation of the toolchain, and using WSL to do it, help on what exactly should be downloaded with sudo apt-get install would be greatly appreciated!

I run:

cd /mnt/c/dev
git clone git://gcc.gnu.org/git/gcc.git
git checkout releases/gcc-9.3.0
cd gcc
./configure --prefix=/mnt/c/dev/gcc-9.3 --enable-languages=c,c++
make -j20
make install

Very often, it simply freezes, and refuse to function again until I restart. When it freeze, it simply doesn't output any text, and instead just shows my input. When I press Ctrl+C, it also just show ^C.

I thought maybe this means that it is running, but giving it lots of time it still is stuck like this. It mainly happens during the configure or the make. When it has been frozen, it is frozen permanently. New windows of it also is frozen. Task manager -> termination -> Still frozen.

Thanks for reading!

EDIT: Added what I have installed by looking at history;

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install gmp
sudo apt-get install libdevel
sudo apt install aptitude
sudo apt install libgmp-dev
sudo apt-get install libmpc-dev
sudo apt-get upgrade
sudo apt-get install lib32gcc-12-dev
apt-get install -y build-essential python3 xorriso genext2fs mtools gnu-efi git automake autoconf wget libgmp-dev libmpfr-dev libmpc-dev flex bison texinfo dosfstools
apt-get install -y build-essential python3 xorriso genext2fs mtools gnu-efi git automake autoconf wget libgmp-dev libmpfr-dev libmpc-dev flex bison texinfo dosfstools
sudo apt install libblas-dev libatlas-base-dev
sudo apt install python3-dev
sudo apt-get install libxml2-dev libxslt1-dev

I added those that I think probably did install successfully. Might be some that weren't actually packages, but that would probably be 1-2 max.

Also in the GNU gcc git I use ./contrib/download_prerequisites.

[I'm ran the commands below]

Changed it to run in the home directory ~ with the commands now instead being;

cd ~
mkdir dev
cd dev
git clone git://gcc.gnu.org/git/gcc.git
cd gcc
git checkout releases/gcc-9.3.0
cd ..
mkdir gcc-9.3.0
cd gcc-9.3.0
./../gcc/configure --prefix=$HOME/dev/gcc-9.3.0 --enable-languages=c,c++ --disable-multilib
make -j20
make install

--disable-multilib: collect2: error: ld returned 1 exit status configure: error: I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.

On a seperate pc I didn't get this issue, and I thought I downloaded the same packages, and also encountered the same freeze effect. So I just use --disable-multilib assuming it isn't the issue.

Also somewhat unrelated to the freezing, the toolchain is now downloaded in \\wsl.localhost\Ubuntu\~\dev\gcc-9.3.0\bin, but after adding that to path I still don't find the kit in VS Code... What might be the issue? I do get msgs after doing make install informing me that I have not linked libraries, and that I need to use either libtool or -LLIBDIR.

❯ wsl -l -v

  • NAME STATE VERSION
  • Ubuntu Running 2

❯ wsl --version

WSL-versjon: 1.2.5.0 Kjerneversjon: 5.15.90.1 WSLg-versjon: 1.0.51 MSRDC-versjon: 1.2.3770 Direct3D-versjon: 1.608.2-61064218 DXCore-versjon: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows-versjon: 10.0.19045.2846

17
  • 1
    Can you check your shell history and find the exact dependencies that you installed? To try to reproduce, I'll need to know what you have in place. Thanks! Apr 21 at 4:46
  • 1
    Also, I recommend trying this in your home directory, rather than in /mnt/c. That may solve the problem, but your comment that "New windows of it also is frozen" has me concerned that the issue might not be quite that easy. Apr 21 at 4:47
  • 1
    It may not matter (or we might get lucky), but the Windows drive is accessed as a network filesystem (Plan 9) from WSL2, and there are permissions, file locking, and performance differences between that drive and the virtual Ext4 filesystem. The gcc build process likely assumes a POSIX compliant filesystem. 99.9% of the time, it doesn't matter, but the gcc build is pretty complex. At the very least, given the performance difference, trying it under ~ will allow it to "fail faster". Apr 22 at 12:12
  • 1
    Does wsl.exe --version return version info, or just the help text? Apr 26 at 1:40
  • 1
    Ok, that gives us something to try at least. You are on a much older WSL release (about 18 months behind) if wsl --version doesn't work. Try installing WSL from the Microsoft Store. That should bring you up to the latest version. Again, we could get lucky and find that whatever issue you are seeing has been fixed. Apr 26 at 10:44

1 Answer 1

1

For now, it seems like I fixed the issue by;

  1. Reinstalling
  2. Removing any path variables that use a path to the Linux subsystem (Z:\)
  3. Using Powershell and wsl command instead of running the Ubuntu app
  4. Installing the libraries
  5. Moving into the Linux subsystem home directory (Bonus: Significantly faster than working in the normal Windows drives. e.g.: /c/dev/...)
  6. Doing the whole GCC build process there

The process for those who may wanna replicate it or encounter the same issue.

  1. Reinstalling

Remove Linux subsystem: https://pureinfotech.com/remove-linux-distro-wsl/

Install Linux subsystem: https://learn.microsoft.com/en-us/windows/wsl/install & https://learn.microsoft.com/en-us/windows/wsl/install-manual

The second installation link is to update to WSL 2 and set it as the default version.

  1. Removing any path variables that use a path to the Linux subsystem (Z:\)

Windows -> Edit the environment variables -> Check user & system path for any entries that use the Z:\ drive. There might be another drive letter for your subsystem instead, which I believe can be checked by going into the explorer -> "This PC" and scrolling down.

  1. Using Powershell and wsl command instead of running the Ubuntu app

Open Powershell and write wsl, and press enter to go use WSL in that Powershell instance. Can go back to Powershell by writing exit.

  1. Installing the libraries
  2. Moving into the Linux subsystem home directory (Bonus: Significantly faster than working in the normal Windows drives. e.g.: /c/dev/...)
  3. Doing the whole GCC build process there

Did all of this a lot of times, and this resulted in me creating a script for it;

Save it as scriptName.sh, use chmod +x /path/to/scriptName.sh to let you run the script, and then run it. It can be run from anywhere with /path/to/scriptName.sh; if it is in the current directory, you can do ./scriptName.sh.

#!/bin/bash

# Give permissions:
# chmod +x /path/to/scriptName.sh
# Run:
# /path/to/scriptName.sh OR cd /path/to/; ./scriptName.sh

# Download packages
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get make -y
sudo apt-get install gcc -y                 # not cross
sudo apt-get install g++ -y
sudo apt-get install make -y
sudo apt-get install bison -y
sudo apt-get install flex -y
sudo apt-get install gawk -y
sudo apt-get install libgmp-dev libgmp3-dev libgmpv4 -y
sudo apt-get install libmpfrc++-dev libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg -y
sudo apt-get install mpc libmpc-dev -y
sudo apt-get install texinfo -y            # optional
sudo apt-get install libcloog-isl-dev -y   # optional
sudo apt-get install build-essential -y
sudo apt-get install glibc-devel -y
sudo apt-get -y install gcc-multilib libc6-i386 -y
sudo apt-get install libz-dev -y

printf "\n\n\n\nFinished downloading packages (except for prerequisites)\n\n\n\n"

# Git repo copy and checkout

cd $HOME

mkdir dev

cd dev

printf "\n\n\n\nMoved into dev\n\n\n\n"

sudo rm -r gcc

git clone git://gcc.gnu.org/git/gcc.git

cd gcc

git checkout releases/gcc-9.3.0

printf "\n\n\n\nMoved into gcc\n\n\n\n"

# Build

./contrib/download_prerequisites

printf "\n\n\n\nFinished downloading prerequisites\n\n\n\n"

./configure                                            \
    --prefix=/usr/                                     \
    --disable-multilib                                 \
    --with-system-zlib                                 \
    --enable-languages=c,c++

make -j$(nproc)

printf "\n\n\n\nFinished make\n\n\n\n"

sudo make install -j$(nproc)

printf "\n\n\n\nFinished make install\n\n\n\n"

A note for the script is that sudo rm -r gcc and git clone git://gcc.gnu.org/git/gcc.git can be commented out to reduce the execution time by a lot. I had several iterations of the script and sometimes had issues with stuff inside /gcc/ already was created, and therefore, changes to, for example, the configure sometimes messed up. Maybe it was just me doing it wrong, but I let it stay in to ensure it works.

It hasn't frozen but runs for a few hours at a time. It might not have fixed the issue, but since it works, it is a solution for now.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .