系统
# cat /etc/redhat-release
CentOS release 6.8 (Final)
1.升级gcc-5.4.0
安装之前系统gcc版本
# gcc -v
Using built-in specs.
Target: x86_64-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-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
1.1 下载安装包wget http://mirrors.nju.edu.cn/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.gz
以下四个文件解压到gcc-5.4.0,并且软链接为mpfr gmp mpc isl
http://mirror.hust.edu.cn/gnu/mpfr/mpfr-2.4.2.tar.gz
http://mirrors.nju.edu.cn/gnu/gmp/gmp-4.3.2.tar.gz
http://mirrors.nju.edu.cn/gnu/mpc/mpc-1.1.0.tar.gz
http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.14.tar.bz2
或者执行以下脚本自动进行
./contrib/download_prerequisites
1.2 进行编译安装
cd ..
mkdir gcc-build-5.4.0
cd gcc-build-5.4.0
../gcc-5.4.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make && make install
gcc -v 此时系统gcc会自动变成gcc-5.4版本
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-5.4.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 5.4.0 (GCC)
添加新gcc的环境变量:export PATH=$PATH:/usr/local/bin
建立新gcc的软链接:sudo ln -s /usr/local/bin/gcc /usr/bin/gcc
2.升级cmake为3.10版本
$ cmake --version
cmake version 2.8.12.2
由于升级了gcc版本,需要更新glibc的库文件,否则会报错
cp /usr/local/lib64/libstdc++.so.6.0.21 /usr/lib64
mv libstdc++.so.6 libstdc++.so.6.bak
ln -s libstdc++.so.6.0.21 libstdc++.so.6
编译并安装cmake-3.10
./bootstrap
gmake && gmake install
yum remove cmake
ln -s /usr/local/bin/cmake /usr/bin/cmake
ln -s /usr/local/bin/cpack /usr/bin/cpack
ln -s /usr/local/bin/ctest /usr/bin/ctest
此时升级后版本如下:
# cmake --version
cmake version 3.10.0-rc4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
比较明显的坑如下:
1.gcc升级后,原有的glibc库会发送改变
yum安装的glibc会在/usr/local/lib64下存在libstdc++.so.6.0.13并软连接到libstdc++.so.6
如果后续编译cmake当调用libstdc++库时,会报错“GLIBCXX_3.4.21‘ not found”,此时执行以下操作,将/usr/local/lib64下的libstdc++库文件链接到/usr/lib64下报错就会消失
# ln -s /usr/local/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6
原文地址:https://blog.51cto.com/mengix/2452368