Ask Your Question
1

Fedora 24: How do I install and change the default gcc compiler version?

asked 2016-10-05 03:43:55 -0500

fedorauser gravatar image

updated 2016-10-05 03:44:37 -0500

I am attempting to install some software using a fork of Linuxbrew known as Cadfaelbrew. (It is used primarily in the HEP industry.)

Unfortunately there is a bug which means Cadfaelbrew does not recognize gcc version 6.2 as supporting c++11.

However Cadfaelbrew does work with gcc version 4.9 on CentOS. (Which is a very similar OS to Fedora, as both are Redhat like OS's.)

To sidestep this problem (I cannot fix the bug myself) I would like to install gcc version 4.9 on my Fedora 24 system (using dnf, probably?).

I then need to change the default gcc compiler so that the command gcc/g++ point to the gcc/g++ version 4.9 compilers rather than the version 6.2 compilers.

How can I do that?

In addition, I would like to know how to revert the changes so that I am able to use gcc/g++ version 6 by default in the future.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-10-05 04:40:14 -0500

hhlp gravatar image

updated 2016-10-05 05:07:43 -0500

Refer "How to install multiple versions of GCC" here in the GNU GCC FAQ.

There's also a white paper here.

you can also use update-alternatives to know that you have 2 C/C++ compilers, create a record for each one, and then configure which one you want to use. This is done with the following:

FOR EXAMPLE 4.3 an 4.4 please change as your need :

First erased the current update-alternatives setup for gcc and g++:

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++ or gcc-++

Install Alternatives

Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10 (or gcc-++)
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20 (or gcc++)

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 or (gcc-++)
sudo update-alternatives --set c++ /usr/bin/g++ (or gcc-++)

Configure Alternatives

The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:

sudo update-alternatives --config gcc
sudo update-alternatives --config g++ or (gcc-++)

or :

If you just want to build things with a different version of gcc, that's easy enough, even with makescripts. For example, you can pass in the version of gcc in the CC environment variable:

CC="gcc-4.5" ./configure
CC="gcc-4.5" make

Regards.,

edit flag offensive delete link more

Comments

Thanks for this - can you explain what the arguments to update-alternatives do? I assume the final number is a priority or something? What is this for?

fedorauser gravatar imagefedorauser ( 2016-10-06 11:41:24 -0500 )edit

@fedorauser yes, is it a priority

hhlp gravatar imagehhlp ( 2016-10-07 03:05:41 -0500 )edit

Why is that needed though? In what situations would a program fall back to a link with lower priority?

fedorauser gravatar imagefedorauser ( 2016-10-11 08:30:27 -0500 )edit

@fedorauser - > Each alternative has a priority associated with it. When a link group is in automatic mode, the alternatives pointed to by members of the group will be those which have the highest priority. from man page

hhlp gravatar imagehhlp ( 2016-10-11 08:55:04 -0500 )edit

update-alternatives doesn't seem to have a --remove-all mode anymore in version 1.8

segfault gravatar imagesegfault ( 2017-03-29 17:51:38 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-10-05 03:43:55 -0500

Seen: 12,088 times

Last updated: Oct 05 '16