The GCC 16.1 compiler is out and I couldn’t wait to get my hands on it. I have just now installed the GCC 16.1 on my Ubuntu machine and quickly compiled a C++26 program and ran it and I was excited to see it went like a charm. So I have jotted down the steps I followed to install the new compiler and a sample program written using C++26 feature reflection, compiling and running it in my Ubuntu machine. Ok, let’s get started then.

Installing GCC 16.1 on Ubuntu

Installing the dependencies

Open a terminal in Ubuntu and run the following command on the terminal:

sudo apt update
sudo apt install -y build-essential wget tar flex bison texinfo libgmp-dev libmpfr-dev libmpc-dev zlib1g-dev

Once the dependencies are installed we can then go ahead and the download the GCC 16 tarball.

Downloading the GCC 16.1 Source Code

wget https://ftp.gnu.org/gnu/gcc/gcc-16.1.0/gcc-16.1.0.tar.xz
tar -xf gcc-16.1.0.tar.xz
cd gcc-16.1.0
./contrib/download_prerequisites

WARNING! Once this is done come out of the source code folder gcc-16.1.0 because trying to compile it inside the source code folder will cause issue. I made the mistake.

So create a seperate folder and follow the instructions as shown below:

cd ~
mkdir gcc-16-build
cd gcc-16-build

Configure the make environment:

../gcc-16.1.0/configure \
--prefix=/opt/gcc-16.1 \
--enable-languages=c,c++ \
--disable-multilib

Then build the source code:

make -j$(nproc)

WARNING! Building the source code took me ages on my Ubuntu desktop, so beware about the time it takes to build the source code as well as it significatly slowed down my system

Once the building is done, install it:

sudo make install

Once the installation is done check the version as follows:

/opt/gcc-16.1/bin/gcc --version
/opt/gcc-16.1/bin/g++ --version
gcc (GCC) 16.1.0
Copyright © 2026 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++ (GCC) 16.1.0
Copyright © 2026 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.

Set the Path

export PATH=/opt/gcc-16.1/bin:$PATH
export LD_LIBRARY_PATH=/opt/gcc-16.1/lib64:$LD_LIBRARY_PATH

Ok, that’s it about the installation of our new guest GCC 16.1. Now time to put it into test.

Compiling your first C++26 Program

I have written a sample C++26 program using C++26’s feature reflection which is as follows:

// test_reflection.cpp
#include <meta>
#include <print>
struct SensorReading
{
int id;
double temperature;
};
int main()
{
constexpr auto reflected_type = ^^SensorReading;
std::println("C++26 reflection test compiled successfully.");
return 0;
}

Compile the Program

Compile the program using the below:

g++ -std=c++26 -freflection test_reflection.cpp -o test_reflection

Run the Program

~$ ./test_reflection
C++26 reflection test compiled successfully.

Yay! that’s our brand new C++26 program running on Ubuntu! Time for you to try now!

My Installation Environment: ~$ uname -a
Linux vbhadra-DQ77MK 6.8.0-110-generic #110~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 27 12:43:08 UTC x86_64 x86_64 x86_64 GNU/Linux

Leave a Reply