Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  11] [ 0]  / answers: 1 / hits: 24592  / 2 Years ago, mon, july 25, 2022, 7:23:13

I have downloaded g++ 4.8 on Ubuntu 12.10 by doing:



sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.8


but when I do:



sudo update-alternatives --config g++


to switch g++ versions it says:



update-alternatives: error: no alternatives for g++.


However if I do:



g++ --version


it says:



g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


How do I set my g++ 4.8 installation to be the default g++?


More From » gcc

 Answers
2

First of all, you must discover where are your 4.8 binaries of all the tools:



$ which gcc-4.8
/usr/bin/gcc-4.8
$ which g++-4.8
/usr/bin/g++-4.8
$ ls /usr/bin/*-4.8
/usr/bin/cpp-4.8 /usr/bin/x86_64-linux-gnu-cpp-4.8
/usr/bin/g++-4.8 /usr/bin/x86_64-linux-gnu-g++-4.8
/usr/bin/gcc-4.8 /usr/bin/x86_64-linux-gnu-gcc-4.8
/usr/bin/gcc-ar-4.8 /usr/bin/x86_64-linux-gnu-gcc-ar-4.8
/usr/bin/gcc-nm-4.8 /usr/bin/x86_64-linux-gnu-gcc-nm-4.8
/usr/bin/gcc-ranlib-4.8 /usr/bin/x86_64-linux-gnu-gcc-ranlib-4.8
/usr/bin/gcov-4.8


So, we have all our binaries, now lets see if some symlinks are available for such binaries:



$ cd /usr/bin
$ ls -l gcc* cpp g++
lrwxrwxrwx 1 root root 7 sep 18 14:02 cpp -> cpp-4.7
lrwxrwxrwx 1 root root 7 abr 22 2013 g++ -> g++-4.7
lrwxrwxrwx 1 root root 7 sep 18 14:02 gcc -> gcc-4.7


As we can see, only cpp, g++ and gcc has symbolic links. We have two options here.



Symlinking



We replace the symlinks with ours, removing the actuals first:



sudo rm /usr/bin/cpp /usr/bin/gcc /usr/bin/g++


Then creating ours



sudo ln -s /usr/bin/cpp-4.8 /usr/bin/cpp
sudo ln -s /usr/bin/gcc-4.8 /usr/bin/gcc
sudo ln -s /usr/bin/g++-4.8 /usr/bin/g++


To revert it back use the same commands but with 4.7 or 4.6 instead



sudo rm /usr/bin/cpp /usr/bin/gcc /usr/bin/g++
sudo ln -s /usr/bin/cpp-4.7 /usr/bin/cpp
sudo ln -s /usr/bin/gcc-4.7 /usr/bin/gcc
sudo ln -s /usr/bin/g++-4.7 /usr/bin/g++

[#28532] Wednesday, July 27, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
issfullus

Total Points: 264
Total Questions: 126
Total Answers: 107

Location: Comoros
Member since Mon, Dec 19, 2022
1 Year ago
;