利用yum升级Centos6的gcc版本,使其支持C++11

下面的可以在centos6下工作,centos7下有问题。可能是因为centos下的scl我是拷贝的文件,没有完全验证centos6下肯定没问题。

https://my.oschina.net/u/583362/blog/682123 和https://www.quyu.net/info/876.html

拷贝其关键内容就是:

1.使用 redhat developer toolset 1.1 的repo,安装GCC

cd /etc/yum.repos.d

wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo

yum --enablerepo=testing-devtools-2-centos-6 install devtoolset-2-gcc devtoolset-2-gcc-c++ 

2. 替换系统中原来的GCC

通过通过第一步会把 GCC 安装到以下目录:

/opt/rh/devtoolset-2/root/usr/bin

接下来需要修改系统的配置,使默认的 gcc 和 g++ 命令使用的是新安装的版本。

ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/local/bin/
hash -r

编译时,提示错误“Error: expecting string instruction after `rep'”,这样解决:yum install devtoolset-2-binutils-devel

开头提到的另一个网页,可以安装gcc5.2版本。摘录如下:

gcc 4.8 安装

curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo
yum install gcc gcc-g++
gcc --version

gcc 4.9 安装

yum install centos-release-scl
yum install devtoolset-3-toolchain -y
scl enable devtoolset-3 bash
gcc --version

gcc 5.2 安装

yum install centos-release-scl
yum install devtoolset-4-toolchain -y
scl enable devtoolset-4 bash
gcc --version

gcc 6 安装

yum install centos-release-scl
yum install devtoolset-6-toolchain -y
scl enable devtoolset-6 bash
gcc --version

scl enable devtoolset-3 bash只是临时覆盖系统原有的GCC引用,如果想永久覆盖,可在root/.bashrc文件中添加source /opt/rh/devtoolset-3/enable

同样不要忘了: yum -y install devtoolset-<n>-binutils-devel, <n>是 2,3,4. 

目前没有devtoolset-5-toolchain,但有devtoolset-6-toolchain

centos7 下可以直接yum安装:

sudo yum install centos-release-scl -y
sudo yum install devtoolset -6 -y
 

更改默认gcc版本

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6.3 40 
sudo update-alternatives --config gcc


转载于:https://www.cnblogs.com/tangxiaosheng/p/7452061.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值