Using GCC10 with Qt on KDE Neon 18

321 Views Asked by At

I would like to play around with some very new C++20 features. Some of them are supported by GCC10 only. Unfortunately the most current release is GCC9.3 so I need to use the unreleased version of GCC10.

I did the following to install it:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt install gcc-10 g++-10

This worked fine. However I am unable to make it the default compiler. As usual I tried:

sudo update-alternatives --config gcc

This says there would be no alternatives. Why?

1

There are 1 best solutions below

0
On

You can do it manually:

cd /usr/local/bin
sudo ln -s /usr/bin/gcc-10 gcc
sudo ln -s /usr/bin/g++-10 g++

Then open a new terminal windows and gcc should refers to gcc-10. It should work for simple cases. If it does not, you will have to create all the appropriate symbolic links for all GCC 10 ecutables and libraries...

I think the best option is to compile yourself GCC 10 and install it in your home directory. This is what I do on my minimalist Gentoo installation, I suppose it will work too on Ubuntu:

mkdir ~/src
cd ~/src
git clone https://github.com/gcc-mirror/gcc.git
mkdir gcc_build
cd gcc_build
../gcc/configure --enable-libsanitizer --prefix=~/usr --with-gcc-major-version-only --disable-bootstrap --enable-language=c,c++,lto
make -j16
make install -j16

Compilation may last about 10 minutes. Consider to adapt the -j16 option to your machine: this is the number of jobs launched simultaneously by make. Using twice the number of parallel thread supported by your CPU is a good choice. Then add appropriate environment variables to your ~/.bashrc file:

export LD_LIBRARY_PATH=~/usr/lib64:~/usr/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=~/usr/lib64:~/usr/lib:$LIBRARY_PATH
export LD_RUN_PATH=~/usr/lib64:~/usr/lib:$LD_RUN_PATH
export PATH=~/usr/bin:$PATH

When you do not want to use gcc-10 any more comment out these lines and open a new terminal.