Every Linux distro seems to include a default compiler that is horribly out of date. Many times this is because academics on standards committees don’t have a clue about the real world. In particular how academics decided without seeking real industry input to force C/C++ compilers to store all integers as 2’s complement. Obviously they’ve never done device interface programming or worked on a Unisys mainframe. Yes, I’ve written about academics and their butchering of language standards before.
Now that the latest version of SciTE requires C++20 this became an issue. I wanted to make some mods to Scintilla and test them in SciTE. The only “clean” machine I had to use was running OpenSuSE Leap 15.5. I didn’t feel like spinning up a VM on something for this work.
For whatever reason, OpenSuSE Leap 15.5 installs gcc-7 and cpp-7 by default when you enable development. I suspect it was the above reason or some other non-kernel-compatible change to the language standard. After installing gcc-11 and cpp-11 via the GUI package manager (or command line if you prefer) you will find they are not the default compilers.
SU vs. sudo
OpenSuSE makes you jump through hoops to add yourself to the sudoers file. (Yes I did it.) They want you to know the root password without having a root account enabled. For those of you running on a Linux distro with that design mentality this will work as-is. Those running on a YABU (Yet Another uBUntu) or non-SU philosophy distros will have to prefix quite a bit with sudo.
roland@localhost:~> su -
Password:
localhost:~ # update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 50
update-alternatives: using /usr/bin/gcc-11 to provide /usr/bin/gcc (gcc) in auto mode
localhost:~ # update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 20
localhost:~ # update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-11 50
update-alternatives: using /usr/bin/cpp-11 to provide /usr/bin/cpp (cpp) in auto mode
localhost:~ # update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-7 20
localhost:~ #
localhost:~ # update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-11 50 auto mode
1 /usr/bin/gcc-11 50 manual mode
2 /usr/bin/gcc-7 20 manual mode
Press <enter> to keep the current choice[*], or type selection number:
localhost:~ # update-alternatives --config cpp
There are 2 choices for the alternative cpp (providing /usr/bin/cpp).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/cpp-11 50 auto mode
1 /usr/bin/cpp-11 50 manual mode
2 /usr/bin/cpp-7 20 manual mode
Press <enter> to keep the current choice[*], or type selection number:
localhost:~ #
localhost:~ # ls /usr/bin/g++*
/usr/bin/g++ /usr/bin/g++-11 /usr/bin/g++-7
localhost:~ # update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 50
update-alternatives: using /usr/bin/g++-11 to provide /usr/bin/g++ (g++) in auto mode
localhost:~ # update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 20
localhost:~ # update-alternatives --config g++
There are 2 choices for the alternative g++ (providing /usr/bin/g++).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/g++-11 50 auto mode
1 /usr/bin/g++-11 50 manual mode
2 /usr/bin/g++-7 20 manual mode
Press <enter> to keep the current choice[*], or type selection number:
localhost:~ #
While that is informative, many of you reading this will be too lazy to pick out the actual commands.
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 20
update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-11 50
update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-7 20
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 50
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 20
update-alternatives --config gcc
update-alternatives --config cpp
update-alternatives --config g++
Use the –config lines to both verify and alter the default compilers as you need. Sadly, in OpenSuSE and most other distros, update-alternatives doesn’t get a record added at time of installation.