华为鲲鹏服务器gcc升级到7.3.0版本
一、首先检查gcc的版本
进入控制台终端执行gcc --version或g++ -v
[root@localhost ~]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
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-44) (GCC)
二、安装gcc7.3.0
本文以7.3.0版本为例。
当查询到的版本不满足要求时,需要安装gcc。
下载gcc7.3.0:https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
下载完成后,将“gcc-7.3.0.tar.gz”放置于“/home”目录下,并解压安装。
cd /home
tar -xvf gcc-7.3.0.tar.gz
三、下载isl、gmp、mpc、mpfr
1、在“gcc-7.3.0”目录下,检查gcc的依赖包是否已下载和安装。
./contrib/download_prerequisites
2、根据需要,下载
“gmp-6.1.0.tar.bz2”
“isl-0.16.1.tar.bz2”
“mpc-1.0.3.tar.gz”
“mpfr-3.1.4.tar.bz2”。
在步骤3.1中检查到存在上述依赖包未下载安装时,请根据需要执行相应的命令下载。
wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
3、 将安装包放置于“/home/gcc-7.3.0”目录下。
4、 把下载好的安装包解压并安装,进入解压后的目录执行
./configure
make
make install
四、编译安装gcc
1、编译gcc。
“-j”参数可利用多核CPU加快编译速度,在本示例中,使用的是16核CPU,所以此处为“-j16”。
可通过下述命令查询CPU核数:
cat /proc/cpuinfo| grep "processor"| wc -l
cd /home/gcc-7.3.0
mkdir gcc-build-7.3.0
cd gcc-build-7.3.0
../configure --enable-checking=release --enable-language=c,c++ --disable-multilib --prefix=/usr
make -j16
2、执行安装。
make install
3、 确定“libstdc++.so”是在“/usr/lib64”目录下。
[root@localhost rz]# cd /usr/lib64/
[root@localhost lib64]# ll | grep libstdc++.so
lrwxrwxrwx. 1 root root 19 Dec 8 14:05 libstdc++.so -> libstdc++.so.6.0.24
lrwxrwxrwx. 1 root root 19 Dec 8 14:05 libstdc++.so.6 -> libstdc++.so.6.0.24
-rwxr-xr-x. 1 root root 1057320 Sep 30 10:40 libstdc++.so.6.0.19
-rwxr-xr-x. 1 root root 11836224 Dec 8 14:05 libstdc++.so.6.0.24
-rw-r--r--. 1 root root 2385 Dec 8 14:05 libstdc++.so.6.0.24-gdb.py
4、确定软连接存在
[root@localhost lib64]# cd /usr/lib64/
[root@localhost lib64]# ll |grep libstdc++.so.6.0.24
lrwxrwxrwx. 1 root root 19 Dec 8 14:05 libstdc++.so -> libstdc++.so.6.0.24
lrwxrwxrwx. 1 root root 19 Dec 8 14:05 libstdc++.so.6 -> libstdc++.so.6.0.24
-rwxr-xr-x. 1 root root 11836224 Dec 8 14:05 libstdc++.so.6.0.24
-rw-r--r--. 1 root root 2385 Dec 8 14:05 libstdc++.so.6.0.24-gdb.py
5、查看版本
gcc --version
[root@localhost ERtpServer]# gcc --version
gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
五、遇到的问题
1、出现了如“error while loading shared libraries: libisl.so.15: cannot open shared object file: No such file or directory”的错误
原因分析
编译过程中找不到libisl.so.15库文件。
处理步骤
步骤 1 执行以下命令,设置软链接。
ln -s /usr/local/lib/libisl.so.15 /usr/lib64/libisl.so.15
ldconfig
步骤 2 重新执行make