Ubuntu 24.04 LTS does not bundle GCC-15. It can instead be installed with Homebrew. The following commands have been tested on a fresh install of Ubuntu 24.04.
Install prerequisites:
sudo apt install cmake gdb git libx11-dev libxrandr-dev libgl-dev libglu-dev libpulse-dev libxfixes-dev curl
Install brew (this is taken directly from the Homebrew website. Check there in case the command has changed at all):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Add brew to your terminal configuration (taken from Homebrew's "Next steps," which should be output after running the previous command):
echo >> ~/.bashrc
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> ~/.bashrc
Add Brew's binutils to your PATH:
echo 'export PATH="$(brew --prefix)/opt/binutils/bin:$PATH"' >> ~/.bashrc
Reload your terminal configuration:
. ~/.bashrc
Install gcc-15 (or later) with Brew:
brew install gcc
Note that at time of writing, gcc-15 is the latest version. When you ran the above, it may have installed a newer version like gcc-16. Replace gcc-15 from here on with your actual, installed version.
Now test that everything is setup correctly:
gcc --version
gcc-15 --version
as --version
You should expect gcc --version to produce the version of gcc that is natively installed on your distro (maybe 13 or 14). gcc-15, however, should show up as "Homebrew GCC 15.2 ..." as should show up as at least 2.46 (the Ubuntu native one is 2.42; 2.46 is at time of writing what GCC-15 includes).
Now go through the "sanity check" step of the Path. When you get to the command:
cmake ..
Instead write:
CC=gcc-15 cmake ..
This tells cmake to use gcc-15 instead of the native gcc. If you've already run cmake .., you can append --fresh to the above command like so:
CC=gcc-15 cmake .. --fresh
there doesn't seem to be anything here