Marco D'oleire
Marco D'oleire

Reputation: 31

update-alternatives --config gcc doesn't change the compiler at all

I've installed gcc-6 on ubuntu 18 (default gcc-7) because cuda toolkits 9 requires this specific version of the compiler. I used this to have alternatives when to use gcc-6 or gcc-7

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100

--slave /usr/bin/g++ g++ /usr/bin/g++-7

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50

--slave /usr/bin/g++ g++ /usr/bin/g++-6

Then I can choose between the two of them as the default compiler

sudo update-alternatives --config gcc

There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

Selection Path Priority Status


*0 /usr/bin/gcc-7 100 auto mode

1 /usr/bin/gcc-6 50 manual mode

2 /usr/bin/gcc-7 100 manual mode

Press enter to keep the current choice[*], or type selection number: 0

I 'm selecting [0], means gcc7. Then i check the version but still is gcc6

gcc --version

gcc (Ubuntu 6.5.0-2ubuntu1~18.04) 6.5.0 20181026

Any idea why it's not working?

Upvotes: 2

Views: 3981

Answers (1)

Marco D'oleire
Marco D'oleire

Reputation: 31

I solved it. The thing when using cuda is that inside cuda folder you have a symbolic link to gcc. This link toke me everytime to gcc-6 instead of gcc-7. I changed the symbolic link, first removing it from cuda folder and then creating a new one which goes directly to gcc-7. In my case

sudo rm /usr/local/cuda-9.0/bin/gcc

sudo rm /usr/local/cuda-9.0/bin/g++

sudo ln -s /usr/bin/gcc-7 /usr/local/cuda-9.0/bin/gcc

sudo ln -s /usr/bin/g++-7 /usr/local/cuda-9.0/bin/g++

Now the compiler is gcc-7 and not gcc-6.

I was expecting a bad behavior of cuda with gcc-7 but everything is working good.

Upvotes: 1

Related Questions