版本信息
Red Hat 5.5 gcc-4.9.4
获取源码包方法,文章结尾有说明!
解决问题
在编译安装的时候碰到“configure: error: ***A compiler with support for c++11 language features is required.” 是因为编译器版本不支持c++11,所以需要安装高版本gcc编译器以支持c++11,下面采用编译源码方式安装。 在编译安装高版本gcc编译器时,碰到“gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0”,所以索性把所有依赖重新安装一遍。
预装环境
$ yum install -y gcc gcc-c++
把源码包上传到/usr/local/software目录
安装gmp
$ cd /usr/local/software
$ tar -zxvf gmp-5.0.2.tar.gz
$ cd gmp-5.0.2
$ ./configure --prefix=/usr/local/ && make && make install && echo "sayok "
安装mpfr
$ cd ..
$ tar -zxvf mpfr-3.1.2.tar.gz
$ cd mpfr-3.1.2
$ ./configure --prefix=/usr/local/ --with-gmp=/usr/local/ && make && make install && echo "say ok"
安装mpc
$ cd ..
$ tar -zxvf mpc-0.9.tar.gz
$ cd mpc-0.9
$ ./configure --prefix=/usr/local/ --with-gmp=/usr/local/ --with-mpfr=/usr/local/ && make && make install && echo "say ok"
安装gcc
$ cd ..
$ tar -zxvf gcc-4.9.4.tar.gz
$ cd gcc-4.9.4
$ ./configure --prefix=/usr/local/gcc-4.9.4 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local
$ make && make install && echo "say ok"
编译安装过程一个多小时
卸载旧版本编译器
$ yum remove gcc gcc-c++
$ ln -s /usr/local/gcc-4.9.4/bin/c++ /usr/bin/c++
$ ln -s /usr/local/gcc-4.9.4/bin/g++ /usr/bin/g++
$ ln -s /usr/local/gcc-4.9.4/bin/gcc /usr/bin/gcc
添加环境变量,修改profile文件,在最末添加如下两句
$ vim /etc/profile
LD_LIBRARY_PATH=/usr/local/gcc-4.9.4/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
$ source /etc/profile
参考链接: 1、详解Linux安装GCC方法 https://www.cnblogs.com/yadongliang/p/6100003.html
|