首先删除了gcc和g ++的当前更新替代设置:

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

安装包

看来gcc-4.3和gcc-4.4都是在安装build-essential之后安装的。但是,我们可以显式安装以下包:

sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4

安装替代品

默认情况下安装符号链接cc和c ++。我们将为gcc和g ++安装符号链接,然后分别将cc和c ++链接到gcc和g ++。

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++

配置替代品

最后一步是配置gcc,g ++的默认命令。交互式地在4.3和4.4之间切换很容易:

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

或者使用脚本切换:

#!/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"
文章作者: 辣比丶小新
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Y丶Zon
教程
喜欢就支持一下吧