Posted inInformation Technology / Thank You Sir May I Have Another

Changing Default Compiler on OpenSuSE

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.

Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++/Qt touchscreen/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the "Zinc It!" book series for John Gordon Burke Publisher, Inc.

A decade later he released a massive (nearly 800 pages) tome "The Minimum You Need to Know to Be an OpenVMS Application Developer" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there "The Minimum You Need to Know" book series was born.

Three years later he wrote his first novel "Infinite Exposure" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of "The Earth That Was" trilogy:
Infinite Exposure
Lesedi - The Greatest Lie Ever Told
John Smith - Last Known Survivor of the Microsoft Wars

When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.