侧边栏壁纸
博主头像
Y丶Zon博主等级

「一笙一个冷悸 &+& 或好或坏……」

  • 累计撰写 79 篇文章
  • 累计创建 101 个标签
  • 累计收到 5 条评论

目 录CONTENT

文章目录

如何选择默认的gcc和g ++版本?

辣比丶小新
2018-12-27 / 0 评论 / 0 点赞 / 53 阅读 / 2982 字

首先删除了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"
0

评论区