在CentOS 6.8 x86_64上利用devtoolset搭建GCC 4.9.2和5.3.1开发环境

下面是在CentOS 6.8 Mac虚拟机上亲自实践的结果:
因为国内防火墙的问题,原有源无法成功安装,需要在下面的文件中更换为国内的源

vim /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information

[centos-sclo-rh]
name=CentOS-$releasever - SCLo rh
# baseurl=http://mirror.centos.org/centos/$releasever/sclo/$basearch/rh/
baseurl=http://mirrors.aliyun.com/centos/$releasever/sclo/$basearch/rh/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

[centos-sclo-rh-testing]
name=CentOS-$releasever - SCLo rh Testing
baseurl=http://buildlogs.centos.org/centos/$releasever/sclo/$basearch/rh/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

然后执行
yum -y install centos-release-scl-rh centos-release-scl
yum check-update (可省略)
yum -y install devtoolset-3-gcc devtoolset-3-gcc-c++
source /opt/rh/devtoolset-3/enable
测试发现当前命令似乎只对本次shell有效,所以可能需要把这条命令加入到~/.bashrc中

如果需要永久覆盖, 可以
echo "source /opt/rh/devtoolset-3/enable" >> /etc/bashrc
source /etc/bashrc
重新登陆terminal生效,发现gcc已经改变
--------------------------------------------------------------------------
继续安装gcc-5.3.1版本, 通过灵活切换是可行的
yum -y install devtoolset-4-gcc devtoolset-4-gcc-c++
source /opt/rh/devtoolset-4/enable

如果要切换到不同的版本,直接运行上面的命令就可以,十分方便。如果需要设置永久生效,直接在/etc/profile或/etc/bashrc中修改。
------------------------------------------------------------------------------
如果你要在开发程序中添加asan内存检测功能,可以继续安装libssan模块
yum -y install devtoolset-4-libasan-devel libssan
如果以前在devtoolset-3-gcc之前安装过libssan,这里就不需要安装了,但是devtoolset-4-libasan-devel必须要安装
否则编译就容易出现的报错





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值