**转载请注明出处**
by.haunying3
https://gcc.gnu.org/mirrors.html 比如 ftp://mirrors-usa.go-parts.com/gcc/releases/gcc-5.2.0/gcc-5.2.0.tar.bz2
2、创建目录并下载文件
mkdir gcc wget ftp://mirrors-usa.go-parts.com/gcc/releases/gcc-5.2.0/gcc-5.2.0.tar.bz2
3、解压 tar -xjvf gcc-5.2.0.tar.bz2 4、安装依赖包【假设已安装——第6步中没有报缺失下列库错误,请跳过此步】
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.0 mkdir /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.3 mkdir /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 checksudo make installexport 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【重新启动失效&仅仅对当前用户有效】
或用以下方法【对全部用户永久生效】
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
5、安装gcc make check 依赖项autogen【假设退出运行ldconfig
which autogen存在则跳过此步】
下载[http://www.gnu.org/software/autogen/]
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运行source /etc/profile./configure --prefix=/usr/local/autogen-5.18.6
make -j 4
make check
make install
sudo update-alternatives --install /usr/bin/autogen autogen /usr/local/autogen-5.18.6/bin/autogen 30
6、创建数据文件夹并编译
cd ..7、建立软连接
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 check make 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
然后运行
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
8、加入库文件路径【黄色为分析过程】
cd /usr/local/gcc-5.2.0 find ./ -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.py ldconfig 验证 ldd mysql【用户程序已经切换到新库】
9、<个人觉得此步没有必要>更新系统动态库链接文件【黄色为分析和说明,此步骤可直接看 *** 作】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卸载】10、遗留问题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成功】
库文件兼容性问题【文档+理论——具体验证】
最后:非常感谢广大网友,你们的博客给了我非常多帮助,对应链接在此不一一列举
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)