GCC 多版本切换
查看系统已安装的 GCC 版本
ls -l /usr/bin/gcc*
root@c98c1b416c01:/home# ls -l /usr/bin/gcc* lrwxrwxrwx 1 root root 21 Jan 16 22:09 /usr/bin/gcc -> /etc/alternatives/gcc -rwxr-xr-x 1 root root 255080 Mar 20 2014 /usr/bin/gcc-4.4 -rwxr-xr-x 1 root root 915736 Oct 4 19:23 /usr/bin/gcc-5 lrwxrwxrwx 1 root root 8 Feb 11 2016 /usr/bin/gcc-ar -> gcc-ar-5 -rwxr-xr-x 1 root root 31136 Oct 4 19:23 /usr/bin/gcc-ar-5 lrwxrwxrwx 1 root root 8 Feb 11 2016 /usr/bin/gcc-nm -> gcc-nm-5 -rwxr-xr-x 1 root root 31136 Oct 4 19:23 /usr/bin/gcc-nm-5 lrwxrwxrwx 1 root root 12 Feb 11 2016 /usr/bin/gcc-ranlib -> gcc-ranlib-5 -rwxr-xr-x 1 root root 31136 Oct 4 19:23 /usr/bin/gcc-ranlib-5 -rwxr-xr-x 1 root root 2189 Dec 3 2015 /usr/bin/gccmakedep
设置 GCC 各版本优先级
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 60 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
设置 G++ 各版本优先级
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 60 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50
版本号 gcc-5、gcc-4.4、g++-5 、g++-4.4 以及 优先级数值 40、50 可以根据自己需要更改。优先级数值范围为0到100。设置好 GCC、G++ 各版本优先级后可进行优先级查看,以及个版本切换。
GCC 各版本切换
sudo update-alternatives --config gcc
root@c98c1b416c01:/home# update-alternatives --config gcc There are 2 choices for the alternative gcc (providing /usr/bin/gcc). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/gcc-4.4 60 auto mode 1 /usr/bin/gcc-4.4 60 manual mode 2 /usr/bin/gcc-5 50 manual mode Press <enter> to keep the current choice[*], or type selection number:
G++ 各版本切换
sudo update-alternatives --config g++
root@c98c1b416c01:/home# update-alternatives --config g++ There are 2 choices for the alternative g++ (providing /usr/bin/g++). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/g++-4.4 60 auto mode 1 /usr/bin/g++-4.4 60 manual mode 2 /usr/bin/g++-5 50 manual mode Press <enter> to keep the current choice[*], or type selection number:
另一种切换方法
在 ~/.bashrc 文件中增添加
alias gcc='/usr/bin/gcc-4.4' alias g++='/usr/bin/g++-4.4'
本作品采用《CC 协议》,转载必须注明作者和本文链接