**转载请注明出处**
by.haunying3
2、创建文件夹并下载文件https://gcc.gnu.org/mirrors.html例如ftp://mirrors-usa.go-parts.com/gcc/releases/gcc-5.2.0/gcc-5.2.0.tar.bz2
mkdir gccwget ftp://mirrors-usa.go-parts.com/gcc/releases/gcc-5.2.0/gcc-5.2.0.tar.bz2
a、安装GMP下载[ https://gmplib.org/ ]wget https://gmplib.org/download/gmp/gmp-6.1.0.tar.bz2解压tar -xjvf gmp-6.1.0.tar.bz2编译并安装cd gmp-6.1.0mkdir /usr/local/gmp-6.1.0./configure --prefix=/usr/local/gmp-6.1.0 --enable-cxxmake -j 4make checksudo make install
b、安装MPFR下载[ http://www.mpfr.org/ ]wget http://www.mpfr.org/mpfr-current/mpfr-3.1.3.tar.gz解压tar -xzvf mpfr-3.1.3.tar.gz编译并安装cd mpfr-3.1.3mkdir /usr/local/mpfr-3.1.3./configure --prefix=/usr/local/mpfr-3.1.3 --with-gmp=/usr/local/gmp-6.1.0注:指定默认路径--with-gmp-include=/usr/local/gmp-6.1.0/include --with-gmp-lib=/usr/local/gmp-6.1.0/libmake -j 4make checksudo make install
c、安装MPC下载[ http://www.multiprecision.org/index.php?prog=mpc&page=download ]wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz解压tar -xzvf mpc-1.0.3.tar.gz编译并安装cd mpc-1.0.3mkdir /usr/local/mpc-1.0.3./configure --prefix=/usr/local/mpc-1.0.3 --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.3make -j 4make checkexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gmp-6.1.0/lib: /usr/local/mpfr-3.1.3/lib:/usr/local/mpc-1.0.3/lib【重启失效&只对当前用户有效】sudo make install
或用下面方法【对所有用户永久生效】
vi /etc/ld.so.conf
将下面内容填入
/usr/local/gmp-6.1.0/lib
/usr/local/mpfr-3.1.3/lib
/usr/local/mpc-1.0.3/lib
退出执行ldconfig
下载[ http://www.gnu.org/software/autogen/ ]6、创建数据目录并编译
wget http://ftp.gnu.org/gnu/autogen/rel5.18.6/autogen-5.18.6.tar.gz
解压
tar -xzvf autogen-5.18.6.tar.gz
cd autogen-5.18.6
mkdir /usr/local/autogen-5.18.6安装autogen依赖项guile【忍无可忍,强烈吐槽linux的依赖关系】wget ftp://ftp.gnu.org/gnu/guile/guile-2.0.7.tar.xzxz -dk guile-2.0.7.tar.xztar -xvf guile-2.0.7.tarcd guile-2.0.7yum search Libtoolyum install libtool-ltdl-devel.x86_64yum search libunistringyum install libunistring-devel.x86_64yum search libffiyum install libffi-devel.x86_64yum search gcyum install gc-devel.x86_64
mkdir /usr/local/guile-2.0.7【因为非默认安装gmp跟configure兼容问题,此处需要安装一个默认的gmp: yum install gmp-devel.x86_64 ——不会对编译gcc的产生影响(手动指定)】./configure --prefix=/usr/local/guile-2.0.7make -jmake check【有几个错误,不过已经麻木,忽略】make installvi /etc/ld.so.conf加入/usr/local/guile-2.0.7/lib执行ldconfigsudo update-alternatives --install /usr/bin/guile guile /usr/local/guile-2.0.7/bin/guile 30杯具的是,不能通过--with-guile=/usr/local/guile-2.0.7/指定编译选项,只能通过以下方式修改vi /etc/profile添加export PKG_CONFIG_PATH=/usr/local/guile-2.0.7/lib/pkgconfig:$PKG_CONFIG_PATH执行./configure --prefix=/usr/local/autogen-5.18.6source /etc/profile
make -j 4
make check
make install
sudo update-alternatives --install /usr/bin/ autogen autogen /usr/local/autogen-5.18.6/bin/ autogen 30
cd ..
mkdir gcc_5.2_build
cd gcc_5.2_build
mkdir /usr/local/ gcc-5.2.0
../gcc-5.2.0/configure --prefix=/usr/local/ gcc-5.2.0 -enable-threads=posix --enable-checking=release --enable-languages=c,c++ --enable-__cxa_atexit --disable-multilib --build=x86_64-redhat-linux --with-gmp= /usr/local/gmp-6.1.0 --with-mpfr= /usr/local/mpfr-3.1.3 --with-mpc= /usr/local/mpc-1.0.3
make -j 4
make checkmake install
如果/usr/bin下的gcc等文件是实体文件而不是链接则需要【否则用update-alternatives添加优先级较低的老版本路径】
mv gcc gcc-4.4.7
mv g++ g++-4.4.7
mv c++ c++-4.4.7
mv cpp cpp-4.4.7
然后执行
8、添加库文件路径【黄色为分析过程】sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-5.2.0/bin/x86_64-redhat-linux-gcc 30sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/gcc-5.2.0/bin/x86_64-redhat-linux-g++ 30sudo update-alternatives --install /usr/bin/c++ c++ /usr/local/gcc-5.2.0/bin/x86_64-redhat-linux-c++ 30sudo update-alternatives --install /usr/bin/cpp cpp /usr/local/gcc-5.2.0/bin/cpp 30
cd /usr/local/gcc-5.2.0find ./ -name *.so*./libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/liblto_plugin.so.0./libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/liblto_plugin.so./libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/liblto_plugin.so.0.0.0./lib64/libgomp-plugin-host_nonshm.so.1.0.0./lib64/libvtv.so.0./lib64/libssp.so.0.0.0./lib64/libgcc_s.so./lib64/libitm.so.1.0.0./lib64/libcc1.so.0./lib64/libstdc++.so.6.0.21-gdb.py./lib64/libssp.so.0./lib64/libstdc++.so.6./lib64/libvtv.so.0.0.0./lib64/libatomic.so.1.1.0./lib64/libgomp.so.1.0.0./lib64/libgomp-plugin-host_nonshm.so./lib64/libubsan.so./lib64/libcc1.so.0.0.0./lib64/libgomp-plugin-host_nonshm.so.1./lib64/liblsan.so.0./lib64/libitm.so./lib64/libquadmath.so./lib64/libgcc_s.so.1./lib64/libquadmath.so.0.0.0./lib64/libquadmath.so.0./lib64/libcilkrts.so./lib64/libasan.so./lib64/libatomic.so.1./lib64/libasan.so.2./lib64/libasan.so.2.0.0./lib64/libcilkrts.so.5.0.0./lib64/libcilkrts.so.5./lib64/libtsan.so.0.0.0./lib64/libstdc++.so.6.0.21./lib64/libgomp.so.1./lib64/libssp.so./lib64/libubsan.so.0./lib64/libatomic.so./lib64/libitm.so.1./lib64/libstdc++.so./lib64/libtsan.so.0./lib64/libtsan.so./lib64/libcc1.so./lib64/liblsan.so.0.0.0./lib64/liblsan.so./lib64/libvtv.so./lib64/libgomp.so./lib64/libubsan.so.0.0.0./lib/gcc/x86_64-unknown-linux-gnu/5.2.0/plugin/libcc1plugin.so.0.0.0./lib/gcc/x86_64-unknown-linux-gnu/5.2.0/plugin/libcc1plugin.so./lib/gcc/x86_64-unknown-linux-gnu/5.2.0/plugin/libcc1plugin.so.0打开配置文件vi /etc/ld.so.conf将路径写入/usr/local/gcc-5.2.0/lib64/usr/local/gcc-5.2.0/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/plugin/usr/local/gcc-5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0执行ldconfig
ldconfig: /usr/local/gcc-5.2.0/lib64/libstdc++.so.6.0.21-gdb.py 不是 ELF 文件 - 它起始的魔数错误。
mv /usr/local/gcc-5.2.0/lib64/libstdc++.so.6.0.21-gdb.py /usr/local/gcc-5.2.0/lib64/bak_libstdc++.so.6.0.21-gdb.pyldconfig验证ldd mysql【用户程序已经切换到新库】
linux-vdso.so.1 => (0x00007fffb5bff000)libncursesw.so.5 => /lib64/libncursesw.so.5 (0x00007f2c6be7f000)libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2c6bc61000)libmysqlclient.so.16 => /usr/lib64/mysql/libmysqlclient.so.16 (0x00007f2c6b8dd000)libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f2c6b6a6000)libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f2c6b48c000)libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f2c6b220000)libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f2c6ae3d000)libz.so.1 => /lib64/libz.so.1 (0x00007f2c6ac26000)libstdc++.so.6 => /usr/local/gcc-5.2.0/lib64/libstdc++.so.6 (0x00007f2c6a899000)libm.so.6 => /lib64/libm.so.6 (0x00007f2c6a615000)libgcc_s.so.1 => /usr/local/gcc-5.2.0/lib64/libgcc_s.so.1 (0x00007f2c6a3fe000)libc.so.6 => /lib64/libc.so.6 (0x00007f2c6a06a000)libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f2c69e49000)libdl.so.2 => /lib64/libdl.so.2 (0x00007f2c69c44000)/lib64/ld-linux-x86-64.so.2 (0x00007f2c6c0b4000)libfreebl3.so => /lib64/libfreebl3.so (0x00007f2c699cb000)libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f2c69787000)libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f2c694a0000)libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f2c6929c000)libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f2c69070000)libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f2c68e64000)libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f2c68c61000)libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f2c68a47000)libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f2c68827000)ldd /bin/ls 【对系统无影响】linux-vdso.so.1 => (0x00007fff0337f000)libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f2f230ef000)librt.so.1 => /lib64/librt.so.1 (0x00007f2f22ee7000)libcap.so.2 => /lib64/libcap.so.2 (0x00007f2f22ce2000)libacl.so.1 => /lib64/libacl.so.1 (0x00007f2f22ada000)libc.so.6 => /lib64/libc.so.6 (0x00007f2f22746000)libdl.so.2 => /lib64/libdl.so.2 (0x00007f2f22541000)/lib64/ld-linux-x86-64.so.2 (0x00007f2f23314000)libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2f22324000)libattr.so.1 => /lib64/libattr.so.1 (0x00007f2f2211f000)
首先找出旧版本安装包【已经在编译后将老版本gcc卸载】rpm -qa | grep 4.4.7db4-4.7.25-18.el6_4.x86_64libstdc++-4.4.7-11.el6.x86_64cpp-4.4.7-11.el6.x86_64libstdc++-devel-4.4.7-11.el6.x86_64libgcc-4.4.7-11.el6.x86_64libgomp-4.4.7-11.el6.x86_64找出安装包对应的动态库文件【不包含有版本路径下的库文件】rpm -ql libstdc++-4.4.7-11.el6.x86_64 | grep lib/usr/lib64/libstdc++.so.6/usr/lib64/libstdc++.so.6.0.13rpm -ql cpp-4.4.7-11.el6.x86_64 | grep lib/lib/cpp/usr/libexec/gcc/usr/libexec/gcc/x86_64-redhat-linux/usr/libexec/gcc/x86_64-redhat-linux/4.4.4/usr/libexec/gcc/x86_64-redhat-linux/4.4.4/cc1/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/usr/share/locale/be/LC_MESSAGES/cpplib.mo/usr/share/locale/ca/LC_MESSAGES/cpplib.mo/usr/share/locale/da/LC_MESSAGES/cpplib.mo/usr/share/locale/de/LC_MESSAGES/cpplib.mo/usr/share/locale/el/LC_MESSAGES/cpplib.mo/usr/share/locale/es/LC_MESSAGES/cpplib.mo/usr/share/locale/fr/LC_MESSAGES/cpplib.mo/usr/share/locale/id/LC_MESSAGES/cpplib.mo/usr/share/locale/ja/LC_MESSAGES/cpplib.mo/usr/share/locale/nl/LC_MESSAGES/cpplib.mo/usr/share/locale/sv/LC_MESSAGES/cpplib.mo/usr/share/locale/tr/LC_MESSAGES/cpplib.mo/usr/share/locale/uk/LC_MESSAGES/cpplib.mo/usr/share/locale/vi/LC_MESSAGES/cpplib.mo/usr/share/locale/zh_CN/LC_MESSAGES/cpplib.mo/usr/share/locale/zh_TW/LC_MESSAGES/cpplib.morpm -ql libstdc++-devel-4.4.7-11.el6.x86_64 | grep lib/usr/include/c++/4.4.4/cstdlib/usr/include/c++/4.4.4/tr1/cstdlib/usr/include/c++/4.4.4/tr1/stdlib.h/usr/include/c++/4.4.4/tr1_impl/cstdlib/usr/lib/gcc/usr/lib/gcc/x86_64-redhat-linux/usr/lib/gcc/x86_64-redhat-linux/4.4.4/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libstdc++.a/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libsupc++.a/usr/lib/gcc/x86_64-redhat-linux/4.4.7/usr/share/doc/libstdc++-devel-4.4.7/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-1998.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-1999.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-2000.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-2001.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-2002.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-2003.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-2004.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-2005.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-2006.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog-2007.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog.bz2/usr/share/doc/libstdc++-devel-4.4.7/ChangeLog~.bz2/usr/share/doc/libstdc++-devel-4.4.7/READMErpm -ql libgcc-4.4.7-11.el6.x86_64 | grep lib/lib64/libgcc_s-4.4.7-20120601.so.1/lib64/libgcc_s.so.1/usr/share/doc/libgcc-4.4.7/usr/share/doc/libgcc-4.4.7/COPYING.LIBrpm -ql libgomp-4.4.7-11.el6.x86_64 | grep lib/usr/lib64/libgomp.so.1/usr/lib64/libgomp.so.1.0.0/usr/share/doc/libgomp-4.4.7/usr/share/doc/libgomp-4.4.7/ChangeLog.bz2/usr/share/info/libgomp.info.gz查看上面筛选出的文件,确认是否为链接文件,以及链接到哪个文件ll /usr/lib64/libstdc++.so.6lrwxrwxrwx. 1 root root 19 11月 10 22:30 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.13ll /usr/lib64/libstdc++.so.6.0.13-rwxr-xr-x. 1 root root 987096 10月 15 2014 /usr/lib64/libstdc++.so.6.0.13ll /lib64/libgcc_s.so.1lrwxrwxrwx. 1 root root 28 1月 28 2015 /lib64/libgcc_s.so.1 -> libgcc_s-4.4.7-20120601.so.1ll /usr/lib64/libgomp.so.1lrwxrwxrwx. 1 root root 16 1月 28 2015 /usr/lib64/libgomp.so.1 -> libgomp.so.1.0.0ll /usr/lib64/libgomp.so.1.0.0-rwxr-xr-x. 1 root root 85264 10月 15 2014 /usr/lib64/libgomp.so.1.0.0进入新版gcc目录查找文件find ./ -name libstdc++.so.6./lib64/libstdc++.so.6ll ./lib64/libstdc++.so.6lrwxrwxrwx. 1 root root 19 11月 7 03:29 ./lib64/libstdc++.so.6 -> libstdc++.so.6.0.21find ./ -name libgcc_s.so.1./lib64/libgcc_s.so.1ll ./lib64/libgcc_s.so.1-rw-r--r--. 1 root root 533684 11月 7 03:29 ./lib64/libgcc_s.so.1find ./ -name libgomp.so.1./lib64/libgomp.so.1ll ./lib64/libgomp.so.1lrwxrwxrwx. 1 root root 16 11月 7 03:30 ./lib64/libgomp.so.1 -> libgomp.so.1.0.0结论 :经比较发现只有 libstdc++.so.6.0.21 版本号较高,且 libgcc_s.so.1 为不同文件【libgomp.so.1.0.0版本号一致,不作处理】操作 :cp /usr/local/gcc-5.2.0/lib64/libstdc++.so.6.0.21 /usr/lib64/ldconfigll /usr/lib64/libstdc++.so.6lrwxrwxrwx. 1 root root 19 11月 11 01:51 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.21可以看到 libstdc++.so.6已经更新重启系统验证系统兼容度【^_^reboot成功】作死更新libgcc_s.so.1[慎重操作](其实按实际情况c库的ABI兼容度更高)cp /usr/local/gcc-5.2.0/lib64/libgcc_s.so.1 /lib64/libgcc_s-5.2.0-20151110.so.1ldconfigll /lib64/libgcc_s.so.1lrwxrwxrwx. 1 root root 28 11月 11 02:00 /lib64/libgcc_s.so.1 -> libgcc_s-5.2.0-20151110.so.1重启系统验证系统兼容度【^_^reboot成功】
库文件兼容性问题【文档+理论——详细验证】
最后:非常感谢广大网友,你们的博客给了我很多帮助,相应链接在此不一一列举