CentOS 升级GCC教程
时间:2014-06-28 00:59 来源:linux.it.net.cn 作者:IT网
本文转载自:http://wgkgood.blog.51cto.com/,对作者深表感谢!
最近由于需求的原因,需要把目前gcc-4.4.4升级到gcc-4.6.1,考虑到有多台的原因,做了一个脚本自动安装结合批量工具分发。
一、安装环境
系统版本:centos6.0X64
原GCC版本:gcc-4.4.4
新GCC版本:gcc-4.6.1
二、正式安装
1、下载安装的源码:
-
如下需要下载以下包:
-
gcc-4.6.1.tar.bz2 gmp-4.3.2.tar.bz2 mpc-0.8.1.tar.gz mpfr-2.4.2.tar.bz2
-
下载地址如下:
-
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/{gmp-4.3.2.tar.bz2,mpc-0.8.1.tar.gz,mpfr-2.4.2.tar.bz2}
-
wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.1/gcc-4.6.1.tar.bz2
-
即可!
2、解压安装:安装有先后顺序:GMP、MPFR、MPC、GCC
1.安装GMP:
-
tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/ ;./configure –prefix=/usr/local/gmp/ &&make &&make install
2.安装MPFR:
-
tar jxf mpfr-2.4.2.tar.bz2 ;cd mpfr-2.4.2/ ;./configure –prefix=/usr/local/mpfr –with-gmp=/usr/local/gmp &&make &&make install
3.安装MPC:
-
tar xzf mpc-0.8.1.tar.gz ;cd mpc-0.8.1 ;./configure –prefix=/usr/local/mpc –with-mpfr=/usr/local/mpfr –with-gmp=/usr/local/gmp &&make &&make install
然后执行如下:
-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/</span>
//这一步很关键,设置变量,不设置后面会报错。
4.安装GCC:
-
tar jxf gcc-4.6.1.tar.bz2 ;cd gcc-4.6.1 ;./configure –prefix=/usr/local/gcc –enable-threads=posix –disable-checking –disable-multilib –enable-languages=c,c++ –with-gmp=/usr/local/gmp –with-mpfr=/usr/local/mpfr/ –with-mpc=/usr/local/mpc/ &&make &&make install
-
安装完毕即可!然后做一个链接就可以使用GCC了
-
mkdir -p /data/backup/`date +%Y%m%d`
-
mv /usr/bin/{gcc,g++} /data/backup/`date +%Y%m%d`
-
-
新建软链接:
-
ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
-
ln -s /usr/local/gcc/bin/g++ /usr/bin/g++
三、测试GCC
直接输入gcc -v 可以查看到gcc 版本为4.6.1和相关的编译参数就ok了!附上一个最简单的安装脚本:
-
#!/bin/sh
-
##auto make install gcc
-
##2012-07-03
-
tar jxf gmp-4.3.2.tar.bz2 &&cd gmp-4.3.2/ ;./configure –prefix=/usr/local/gmp/ &&make &&make install
-
-
sleep 1
-
cd ../ ;tar jxf mpfr-2.4.2.tar.bz2 ;cd mpfr-2.4.2/ ;./configure –prefix=/usr/local/mpfr –with-gmp=/usr/local/gmp &&make &&make install
-
-
cd ../ ;tar xzf mpc-0.8.1.tar.gz ;cd mpc-0.8.1 ;./configure –prefix=/usr/local/mpc –with-mpfr=/usr/local/mpfr –with-gmp=/usr/local/gmp &&make &&make install
-
-
cd ../ ;tar jxf gcc-4.6.1.tar.bz2 ;cd gcc-4.6.1 ;./configure –prefix=/usr/local/gcc –enable-threads=posix –disable-checking –disable-multilib –enable-languages=c,c++ –with-gmp=/usr/local/gmp –with-mpfr=/usr/local/mpfr/ –with-mpc=/usr/local/mpc/
-
-
if
-
[ $? -eq 0 ];then
-
echo “This gcc configure is success”
-
else
-
echo “This gcc configure is failed”
-
fi
-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib:/usr/local/gmp/lib:/usr/local/mpfr/lib/
-
-
make && make install
-
-
[ $? -eq 0 ]&&echo This is make install success
////--------------------------------------------------------------------------------------------------------------------------------------------------------------
configure: error: cannot compute suffix of object files: cannot compile
Indeed, adding the MPFR and GPM lib directories to LD_LIBRARY_PATH solves theproblem. For some reason I thought configure would handle this for me since Igave it --with-gmp and --with-mpfr settings. Would have been nice if configuretested for this and given a helpful error. In any event I'll close this out asan invalid bug report.
需要安装gmp与mpfr并且需要在.bash_profile(一般在/root目录下)配置LD_LIBRARY_PATH,把GMP与MPFR对应的lib配置上如:LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpfr/2.4.0/lib:/usr/local/gmp/4.2.2/lib
export LD_LIBRARY_PATH一定要重启生效或者使用 source /root/.bash_profile
error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
1、找到 libXXX.so.X的路径,比如/usr/local/xxx/lib
2、cd /etc
3、gedit ld.so.conf
4、添加/usr/local/xxx/lib
5、ldconfig
(责任编辑:IT)
本文转载自:http://wgkgood.blog.51cto.com/,对作者深表感谢! 最近由于需求的原因,需要把目前gcc-4.4.4升级到gcc-4.6.1,考虑到有多台的原因,做了一个脚本自动安装结合批量工具分发。
一、安装环境
二、正式安装
2、解压安装:安装有先后顺序:GMP、MPFR、MPC、GCC 1.安装GMP:
2.安装MPFR:
3.安装MPC:
然后执行如下:
//这一步很关键,设置变量,不设置后面会报错。 4.安装GCC:
三、测试GCC
////-------------------------------------------------------------------------------------------------------------------------------------------------------------- configure: error: cannot compute suffix of object files: cannot compile Indeed, adding the MPFR and GPM lib directories to LD_LIBRARY_PATH solves theproblem. For some reason I thought configure would handle this for me since Igave it --with-gmp and --with-mpfr settings. Would have been nice if configuretested for this and given a helpful error. In any event I'll close this out asan invalid bug report.
需要安装gmp与mpfr并且需要在.bash_profile(一般在/root目录下)配置LD_LIBRARY_PATH,把GMP与MPFR对应的lib配置上如:LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpfr/2.4.0/lib:/usr/local/gmp/4.2.2/lib
error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file 1、找到 libXXX.so.X的路径,比如/usr/local/xxx/lib 2、cd /etc 3、gedit ld.so.conf 4、添加/usr/local/xxx/lib 5、ldconfig (责任编辑:IT) |