lenmom

博客园 首页 新随笔 联系 订阅 管理

1. 安装必备

yum groupinstall "Development Tools"
yum install glibc-static libstdc++-static
 
2. 编译安装 gcc 
another place recommendated is ustc opensouce mirror https://mirrors.ustc.edu.cn/gnu/gcc/
 
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-7.3.0/gcc-7.3.0.tar.gz
tar -zxvf  gcc-7.3.0
cd gcc-7.3.0
./contrib/download_prerequisites   #安装依赖库,以前升级gcc非常麻烦,因为gcc依赖了mpfr、gmp、mpc 和isl共四个库,下载也麻烦 ,现在简单了
mkdir build
cd build
#在gcc目录,执行配置命令:               ./configure  --prefix=/usr/local/gcc7.3.0 --enable-multilib;
#如果只需要支持c,c++编译器,则执行配置命令:./configure  --prefix=/usr/local/gcc7.3.0 --disable-multilib --enable-languages=c,c++
# –enable-checking=release 增加一些检查,也可以–disable-checking生成的编译器在编译过程中不做额外检查
#–enable-languages=c,c++ 你要让你的gcc支持的编程语言
#–disable-multilib 取消多目标库编译(取消32位库编译)
../configure --prefix=/usr/local/gcc7.3.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib
make    # or make -j 4 which could determin the parallel compiling job number.
make install   #here would install to the folder /usr/local/gcc7.3.0 which is specified by argument --prefix

 

optional step:

uninstall lower version of gcc if you has already installed in the system.

rpm -q gcc       #query if gcc has installed
rpm -q gcc-c++   #query if gcc-c++ has installed 
rpm -e   {package name which has listed if you have gcc installed, on centos 7, it maybe list as follows}
#gcc-4.8.5-16.el7_4.2.x86_64
#gcc-c++-4.8.5-16.el7_4.2.x86_64

 

3. add gcc to the system path

vim /etc/profile
add the following content at the end of file:
export PATH=$PATH:/usr/local/gcc7.3.0/bin

or just create a soft link to /usr/bin

sudo ln -s /usr/local/gcc7.3.0/bin/gcc /usr/bin/gcc
sudo ln -s /usr/local/gcc7.3.0/bin/g++ /usr/bin/g++

 

 4. view the gcc version

gcc --version
g++ --version

output:

 

 4. FAQ

/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21’ not found (required

solution:

find / -name libstdc++.so*

output:

/usr/lib64/libstdc++.so.6
/usr/lib64/libstdc++.so.6.0.19
/usr/lib64/libstdc++.so.6.0.24
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.py
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyc
/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.19-gdb.pyo
/usr/local/lib64/libstdc++.so.6.0.24
/usr/local/lib64/libstdc++.so.6
/usr/local/lib64/libstdc++.so
/usr/local/lib64/libstdc++.so.6.0.24-gdb.py

找到这个这个目录下面的libstdc++.so.6.0.xx,我的是24

cp /usr/local/lib64/libstdc++.so.6.0.24 /usr/lib64
ldconfig   #this is required 

 

5. Alternative solution( not recommondated)

5.1 install devtoolset-6

sudo yum install centos-release-scl
sudo yum install devtoolset-6
scl enable devtoolset-6 bash
sudo yum list devtoolset-6\*

5.2. change default gcc version using command like:

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

if u don't want gcc 6 as your default gcc version, you can enable it  just in  the current terminal:

scl enable devtoolset-6 bash

 

 

reference:
https://www.cnblogs.com/dalanjing/p/10618575.html

posted on 2019-08-08 08:22  老董  阅读(725)  评论(0编辑  收藏  举报