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.
cd gcc-7.3.
./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 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 , it maybe list as follows}
#gcc-4.8.-.el7_4..x86_64
#gcc-c++-4.8.-.el7_4..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. /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-
scl enable devtoolset- bash
sudo yum list devtoolset-\*

5.2. change default gcc version using command like:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6.3
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- bash

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

最新文章

  1. 常用Linux命令收集
  2. TopCoder SRM 639 Div.2 500 AliceGameEasy --乱搞
  3. 【Spring】搭建最简单的Spring MVC项目
  4. poj1733Parity game
  5. SQL实现数组的功能
  6. JSP 客户端请求
  7. System.Web.Optimization找不到引用
  8. 错误处理php
  9. jquery-ui 中treegird 逐步加载
  10. redis maxmemory设置
  11. js_day14
  12. 基于visual Studio2013解决算法导论之002归并排序
  13. FZU 1686(重复覆盖)
  14. java.net.ConnectException connect refured
  15. Cocos2d-x 多分辨率支持
  16. [OpenGL]配置GLFW
  17. Maven第四篇【私有仓库、上传jar包、引用私服jar包、上传本地项目到私服】
  18. ASP.NET Core轻松入门之Middleware管道模型
  19. Jenkins结合.net平台之Web项目编译
  20. python面试题(一)

热门文章

  1. 题解 UVa11889
  2. Django REST framework认证权限和限制和频率
  3. [TypeScript ] Using the Null Coalescing operator with TypeScript 3.7
  4. Hive 调优
  5. python - 使用psutils
  6. Qt同步线程(QMutex QMutexLocker QReadWriteLock QSemaphore QWaitCondition )
  7. 洛谷 P2894 [USACO08FEB]酒店
  8. 机器学习实战(1)- KNN
  9. 如何手动安装WordPress主题和插件(Linux)
  10. Python里面如何生成随机数?