Creating update-alternatives to switch between multiple installed gcc

This is something that had been bugging me for many, many years…

We can install multiple versions of gcc from the OSS and from side by side so there is no conflict, but then the question was how to configure a script to reference the correct gcc?

I’d even submitted a feature request to the bugzilla asking for someone to create an update-alternatives for gcc.

This is an extremely acute problem in Tumbleweed because although bleeding edge compilers are installed by default, most software assume the current stable or older compilers are what’s available.

Recently I came across update-alternatives for gcc used in a software project and when I saw it, it was one of those head-slapping moments… The compiled gcc is very simple (only a single binary with no massive spiderweb of dependent links like Java) and so is easily implemented.

So, I wrote up a Wiki page how to do this very simple thing that is asked all the time in these Forums

And yes, I <still> say that every gcc that’s distributed through an openSUSE repo should automatically install its update-alternatives, especially now that we know it’s so simple to do.


I’ve always just set the version via CC or CXX flags or whatever permutation the source requires.

But, would manually setting those flags be something easily explained to someone who doesn’t compile C any more than occassionally, and can save the setting so the path and file names don’t have to be looked up each time?

The advantage of course when using update-alternatives is that once set up, the User doesn’t need to know or remember details, he simply switches between available options.