在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必须要安装
否则编译就容易出现的报错

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native