gcc 5.2.0 编译安装笔记-20151110

gcc 5.2.0 编译安装笔记-20151110,第1张

gcc 5.2.0 编译安装笔记-20151110

**转载请注明出处**

by.haunying3

系统版本号 CentOS-6.6-x86_64-minimal 编译器 gcc-4.4.7通过yum安装 rpm -qa | grep gcc gcc-4.4.7-11.el6.x86_64 libgcc-4.4.7-11.el6.x86_64 gcc-c++-4.4.7-11.el6.x86_64 安装新版 1、选择一个地址
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-cxx
make -j 4
make check
sudo 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/lib
make -j 4
make check
sudo 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.3
mkdir /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.3
make -j 4
make check
sudo make install

export 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

退出运行ldconfig

5、安装gcc make check 依赖项autogen【假设
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.xz
xz -dk guile-2.0.7.tar.xz
tar -xvf guile-2.0.7.tar
cd guile-2.0.7
yum search Libtool
yum install libtool-ltdl-devel.x86_64
yum search libunistring
yum install libunistring-devel.x86_64
yum search libffi
yum install libffi-devel.x86_64
yum search gc
 yum 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.7
make -j
make check【有几个错误。


只是已经麻木,忽略】

make install
vi /etc/ld.so.conf
增加
/usr/local/guile-2.0.7/lib
运行
ldconfig
sudo 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 ..

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
7、建立软连接
假设/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 30
sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/gcc-5.2.0/bin/x86_64-redhat-linux-g++ 30
sudo update-alternatives --install /usr/bin/c++ c++ /usr/local/gcc-5.2.0/bin/x86_64-redhat-linux-c++ 30
sudo 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【用户程序已经切换到新库】

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)
9、<个人觉得此步没有必要>更新系统动态库链接文件【黄色为分析和说明,此步骤可直接看 *** 作】

首先找出旧版本号安装包【已经在编译后将老版本号gcc卸载】
rpm -qa | grep 4.4.7
db4-4.7.25-18.el6_4.x86_64
libstdc++-4.4.7-11.el6.x86_64
cpp-4.4.7-11.el6.x86_64
libstdc++-devel-4.4.7-11.el6.x86_64
libgcc-4.4.7-11.el6.x86_64
libgomp-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.13
rpm -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.mo
 rpm -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/README
rpm -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.LIB
rpm -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.6
lrwxrwxrwx. 1 root root 19 11月 10 22:30 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.13
ll /usr/lib64/libstdc++.so.6.0.13
-rwxr-xr-x. 1 root root 987096 10月 15 2014 /usr/lib64/libstdc++.so.6.0.13
ll /lib64/libgcc_s.so.1
lrwxrwxrwx. 1 root root 28 1月  28 2015 /lib64/libgcc_s.so.1 -> libgcc_s-4.4.7-20120601.so.1
ll /usr/lib64/libgomp.so.1
lrwxrwxrwx. 1 root root 16 1月  28 2015 /usr/lib64/libgomp.so.1 -> libgomp.so.1.0.0
ll /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.6
ll ./lib64/libstdc++.so.6
lrwxrwxrwx. 1 root root 19 11月  7 03:29 ./lib64/libstdc++.so.6 -> libstdc++.so.6.0.21
find ./ -name libgcc_s.so.1
./lib64/libgcc_s.so.1
ll ./lib64/libgcc_s.so.1
-rw-r--r--. 1 root root 533684 11月  7 03:29 ./lib64/libgcc_s.so.1
find ./ -name libgomp.so.1
./lib64/libgomp.so.1
ll ./lib64/libgomp.so.1
lrwxrwxrwx. 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/
ldconfig
ll /usr/lib64/libstdc++.so.6
lrwxrwxrwx. 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.1
 ldconfig
ll /lib64/libgcc_s.so.1
lrwxrwxrwx. 1 root root 28 11月 11 02:00 /lib64/libgcc_s.so.1 -> libgcc_s-5.2.0-20151110.so.1
重新启动系统验证系统兼容度【^_^reboot成功】
10、遗留问题
库文件兼容性问题【文档+理论——具体验证】


最后:非常感谢广大网友,你们的博客给了我非常多帮助,对应链接在此不一一列举

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/587990.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存