https://blog.csdn.net/zhaomax/article/details/87807711
1、环境:arm架构的centos6.5系统服务器
2、查看当前的gcc版本:gcc -v
[root@aarch64vm-centos74-011 ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/4.8.5/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-aarch64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-aarch64-redhat-linux/cloog-install --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
3、下载gcc 7.4.0的源码:https://mirrors.ustc.edu.cn/gnu/gcc/gcc-7.4.0/gcc-7.4.0.tar.gz
4、将源码上传至服务器然后解压
[root@aarch64vm-centos74-010 ~]# mkdir -p /usr/local/gcc
[root@aarch64vm-centos74-010 ~]# ls /usr/local/
bin boost cmake doc etc games gcc include lib lib64 libexec man maven mysql sbin share src tomcat
[root@aarch64vm-centos74-010 ~]# ls
anaconda-ks.cfg boost_1_59_0.tar.gz jdk1.8.0_161 mysql-5.7.19.tar.gz spark-1.6.1-bin-without-hadoop.tgz
apache-maven-3.3.9-bin.tar.gz cmake-2.8.5.tar.gz jdk-8u161-linux-arm64-vfp-hflt.tar.gz scala-2.11.7.tgz spark-2.1.0-bin-hadoop2.7.tgz
apache-tomcat-8.0.53.tar.gz gcc-7.4.0.tar.gz mysql-5.7.19 scala-2.12.6.tgz
[root@aarch64vm-centos74-010 ~]# tar -xvf gcc-7.3.0.tar.gz -C /usr/local/gcc/
5、解压完成后,编译安装gcc源码
(1)进入gcc 7.3.0目录,运行 download_prerequisites 脚本 。
[root@aarch64vm-centos74-010 ~]# cd /usr/local/gcc/
[root@aarch64vm-centos74-010 gcc]# ls
gcc-7.3.0
[root@aarch64vm-centos74-010 gcc]# cd gcc-7.4.0/
[root@aarch64vm-centos74-010 gcc-7.4.0]# ls
ABOUT-NLS config-ml.in COPYING3 gnattools libada libffi libitm libstdc++-v3 lto-plugin Makefile.in NEWS
ChangeLog config.rpath COPYING3.LIB gotools libatomic libgcc libmpx libtool-ldflags ltoptions.m4 Makefile.tpl README
ChangeLog.jit config.sub COPYING.LIB include libbacktrace libgfortran libobjc libtool.m4 ltsugar.m4 MD5SUMS symlink-tree
ChangeLog.tree-ssa configure COPYING.RUNTIME INSTALL libcc1 libgo liboffloadmic libvtv ltversion.m4 missing ylwrap
compile configure.ac depcomp install-sh libcilkrts libgomp libquadmath ltgcc.m4 MAINTAINERS mkdep zlib
config contrib fixincludes intl libcpp libhsail-rt libsanitizer ltmain.sh maintainer-scripts mkinstalldirs
config.guess COPYING gcc LAST_UPDATED libdecnumber libiberty libssp lt~obsolete.m4 Makefile.def move-if-change
[root@aarch64vm-centos74-010 gcc-7.4.0]# ./contrib/download_prerequisites
2018-07-18 16:06:03 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2018-07-18 16:08:29 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2018-07-18 16:09:25 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [1]
2018-07-18 16:12:42 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2 [1626446] -> "./isl-0.16.1.tar.bz2" [1]
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: OK
isl-0.16.1.tar.bz2: OK
All prerequisites downloaded successfully.
[root@aarch64vm-centos74-010 gcc-7.4.0]#
(2)建立编译输出目录,将所有的中间文件都放到该目录中。
这里建目录的时候,在当前gcc解压目录下建,否则这里所有命令行的路径都要修改。
获取这四个包时,可能有错误,无法识别这个包的状态啥的,没事,删了再来一遍就行了。
[root@aarch64vm-centos74-010 gcc-7.4.0]# mkdir gcc-build-7.3.0
[root@aarch64vm-centos74-010 gcc-7.4.0]# cd gcc-build-7.3.0/
[root@aarch64vm-centos74-010 gcc-build-7.4.0]# cp ../gmp-6.1.0.tar.bz2 ./
[root@aarch64vm-centos74-010 gcc-build-7.4.0]# cp ../mpfr-3.1.4.tar.bz2 ./
[root@aarch64vm-centos74-010 gcc-build-7.4.0]# cp ../mpc-1.0.3.tar.gz ./
[root@aarch64vm-centos74-010 gcc-build-7.4.0]# cp ../isl-0.16.1.tar.bz2 ./
[root@aarch64vm-centos74-010 gcc-build-7.4.0]# ls
gmp-6.1.0.tar.bz2 isl-0.16.1.tar.bz2 mpc-1.0.3.tar.gz mpfr-3.1.4.tar.bz2
[root@aarch64vm-centos74-010 gcc-build-7.4.0]#
(3)配置 :
在当前目录执行,这个目录下 gcc-build-7.3.0
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
参数解释:
--enable-checking=release //增加一些检查,也可以–disable-checking生成的编译器在编译过程中不做检查;
--enable-languages=c,c++ //让gcc支持的编程语言 ;
--disable-multilib //取消多目标库编译(取消32位库编译)。
(4)make编译
当前目录执行:make -j4
(编译时间较长,耐心等待!!!!!!!)
(5)卸载旧版本的gcc,安装gcc7.3.0
rpm -q gcc
rpm -q gcc-c++
根据执行输出的包名执行
rpm -e [包名]
[root@localhost ~]# rpm -q gcc
gcc-4.8.5-28.el7_5.1.aarch64
[root@localhost ~]# rpm -q gcc-c++
gcc-c++-4.8.5-28.el7_5.1.aarch64
[root@localhost ~]# rpm -e gcc-c++-4.8.5-28.el7_5.1.aarch64
[root@localhost ~]# rpm -e gcc-4.8.5-28.el7_5.1.aarch64
进入make的gcc目录进行安装:make install -j8
(6)验证
[root@localhost ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/aarch64-unknown-linux-gnu/7.4.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 7.4.0 (GCC)
[root@localhost ~]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/aarch64-unknown-linux-gnu/7.4.0/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 7.4.0 (GCC)
[root@localhost ~]# which gcc
/usr/local/bin/gcc
[root@localhost ~]#
安装成功!!!
编译遇到问题遇到问题:
解决办法:
https://www.cnblogs.com/godfather007/p/10444270.html
算了,还是别升级了,还是升级centos吧,太难搞了