ubuntu 里切换 gcc,g++ 的版本
2017-08-10 15:43
603 查看
https://askubuntu.com/questions/26498/choose-gcc-and-g-version
https://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu https://codeyarns.com/2015/02/26/how-to-switch-gcc-version-using-update-alternatives/
关于 update-alternatives 命令的帮助: http://www.cnblogs.com/welhzh/p/7339632.html
First erased the current update-alternatives setup for gcc and g++:
Install Packages
It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:
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.
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:
Or switch using script:
[/code]
Here's a complete example of jHackTheRipper's answer for the TL;DR crowd. :-) In this case, I wanted to run g++-4.5 on an Ubuntu system that defaults to 4.6. As
Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:
(Note the use of
https://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu https://codeyarns.com/2015/02/26/how-to-switch-gcc-version-using-update-alternatives/
关于 update-alternatives 命令的帮助: http://www.cnblogs.com/welhzh/p/7339632.html
First erased the current update-alternatives setup for gcc and g++:
sudo update-alternatives --remove-all gcc sudo update-alternatives --remove-all g++
Install Packages
It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:
sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4
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 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20 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 sudo update-alternatives --set c++ /usr/bin/g++
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 switch using script:
#!/bin/sh if [ -z "$1" ]; then echo "usage: $0 version" 1>&2 exit 1 fi if [ ! -f "/usr/bin/gcc-$1" ] || [ ! -f "/usr/bin/g++-$1" ]; then echo "no such version gcc/g++ installed" 1>&2 exit 1 fi update-alternatives --set gcc "/usr/bin/gcc-$1" update-alternatives --set g++ "/usr/bin/g++-$1"
[/code]
Here's a complete example of jHackTheRipper's answer for the TL;DR crowd. :-) In this case, I wanted to run g++-4.5 on an Ubuntu system that defaults to 4.6. As
root:
apt-get install g++-4.5 update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100 update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.5 50 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50 update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100 update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.5 50 update-alternatives --set g++ /usr/bin/g++-4.5 update-alternatives --set gcc /usr/bin/gcc-4.5 update-alternatives --set cpp-bin /usr/bin/cpp-4.5
Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:
update-alternatives --auto g++ update-alternatives --auto gcc update-alternatives --auto cpp-bin
(Note the use of
cpp-bininstead of just
cpp. Ubuntu already has a
cppalternative with a master link of
/lib/cpp. Renaming that link would remove the
/lib/cpplink, which could break scripts.)
相关文章推荐
- Ubuntu14.04下gcc/g++版本切换
- Ubuntu gcc/g++ 版本切换
- ubuntu中gcc、g++版本切换
- ubuntu下gcc、g++和gfortran版本切换
- Ubuntu: Linux系统下gcc(g++)任意版本切换
- ubuntu下安装低级版本gcc/g++ 并随意切换
- ubuntu下手工切换低版本GCC
- Ubuntu下两个gcc版本切换
- Ubuntu 下切换gcc版本
- linux不同gcc/G++版本之间的切换
- 切换gcc与g++版本
- Ubuntu 中安装低版本的gcc/g++
- Ubuntu 中安装低版本的gcc/g++
- Ubuntu下切换GCC版本
- ubuntu下手工切换gcc版本
- linux 中切换gcc 和 g++版本
- 升级ubuntu中的gcc和g++版本
- ubuntu下多个gcc版本切换
- 升级ubuntu中的gcc和g++版本
- Ubuntu下两个gcc版本切换