My programming ramblings

Building GCC 9 on Windows Subsystem for Linux

Posted on May 4, 2017 by Paul

Updated 4 May 2019

In this article, I will show you how to compile from sources GCC 9.1 on WSL, Windows Subsystem for Linux with Ubuntu 18.04. The default version of GCC, at the time of this writing, is 7.3 which is pretty old. GCC 9.1 has complete support for C++11, C++14, C++17 and experimental support for C++2a.

GCC 9.1 has C++14 support enabled by default. If you want to try the new C++17 support use the -std=c++17 flag, example:

1 g++-9.1 -std=c++17 test.cpp -o test

I assume that you have a working and updated WSL installation on your Windows 10 machine. If this is not the case, check my previous article.

First, start WSL, use the Ubuntu 18.04 application console or write ubuntu1804 in a Command Prompt window. Let’s make sure that you have an up to date system, start WSL and write:

At this point, we can configure the build. In order to keep the system clean, we will use /usr/local/gcc-9.1 for the installation folder and append the suffix -9.1 to the GCC compilers. You typically don’t want to mess the system’s default GCC because other packages may depend on this.

Now, we are ready to build GCC, you typically want to pass twice the number of your computer cores to the make command in order to speed up the build. I have a quad-core system, so I will use 8 parallel jobs to build GCC:

1 make -j 8

Depending on the speed of your computer the build phase could take from about 30 minutes to a few hours.

Once the above phase is finished, you can install the built GCC with:

1 sudo make install-strip

If you want to permanently add the compilers to your system’s path, use the next commands:

Disclaimer:All data and information provided on this site is for informational purposes only. solarianprogrammer.com makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis. solarianprogrammer.com does not collect any personal information about its visitors except that which they provide voluntarily when leaving comments. This information will never be disclosed to any third party for any purpose. Some of the links contained within this site have my referral id, which provides me with a small commission for each sale. Thank you for understanding.