Skip to content

Instantly share code, notes, and snippets.

@virtualritz
Last active September 13, 2024 13:51
Show Gist options
  • Save virtualritz/b0c2890c7cde9c220536f11502983e2d to your computer and use it in GitHub Desktop.
Save virtualritz/b0c2890c7cde9c220536f11502983e2d to your computer and use it in GitHub Desktop.
Fixing a broken C/C++ tooling on Ubuntu

Fixing Broken C/C++ Tooling on Ubuntu

Here we're assuming you want to have gcc versions 13 & 14 and clang versions 16 & 17 installed side by-side. Adjust to the versions you're installing.

You may also wish to adjust the priority (the last number in the update-alternatives commands below). A higher number means a higher priority.

We also assume you have previous broken installs of those. If this is not the case, replace reinstall with install in the below commands.

  1. Install compilers:

    sudo apt reinstall gcc-13 g++-13 gcc-14 g++14 clang-16 clang-17
    
  2. Install libs & headers:

    sudo apt reinstall libstdc++-13-dev libstdc++-14-dev libclang-16-dev libclang-17-dev
    
  3. Set up symlinks manually:

    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 10
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 10
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 20
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 20
    sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
    sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
    sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-16 10
    sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 20
    
  4. Set the default C & C++ Compilers:

    sudo update-alternatives --set cc /usr/bin/gcc
    sudo update-alternatives --set c++ /usr/bin/g++
    

After this you should also be able to configure your defaults by running one of those:

sudo update-alternatives --config <tool>

Where <tool> is one of gcc, g++, clang, clang++, cc or c++.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment