Chinaunix首页 | 论坛 | 博客
  • 博客访问: 584686
  • 博文数量: 104
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1559
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-21 00:58
个人简介

锻炼精神,首先要锻炼肉体

文章分类

全部博文(104)

文章存档

2018年(1)

2016年(1)

2015年(101)

2014年(1)

我的朋友

分类: 系统运维

2015-06-14 10:32:02

使用的 linux 内核支持的 gcc 版本是 4.7 ,并不能全面的支持  c++11 中的新特性,所以手动把 gcc 升级到 4.8 。
gcc 的编译与安装需要依赖三个文件 gmp , mpfr , mpc , 其中这三个文件之间也有一定的依赖关系 : mpfr 依赖 gmp , mpc 依赖 gmp 和 mpfr . 
手动安装之后,把安装过程整理成脚本如下所示:


点击(此处)折叠或打开

  1. #!/bin/sh

  2. #first create HOMES for new installing softwares store their binary executable files

  3. GMP_HOME='/usr/local/gmp-6.0.0'
  4. MPFR_HOME='/usr/local/mpfr-3.2.1'
  5. MPC_HOME='/usr/local/mpc-1.0.3'
  6. GCC_HOME='/usr/local/gcc-4.8.2'

  7.  


  8. #download each source file to the corresponding path
  9. tempfile=`mktemp download.XXXXX`

  10. echo 'here we create a file '

  11. exec 3>$tempfile

  12. echo ''>&3

  13. echo 'http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.xz'>&3

  14. echo 'ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz'>&3

  15. echo ''>&3

  16. echo 'here we begin download corresponding files'

  17. wget -i download.*


  18. rm -f download.*


  19. #decompression each source file package

  20. tar -xzf gcc-4.8.2.tar.gz &&

  21. tar -xzf mpc-1.0.3.tar.gz &&

  22. xz -d mpfr-3.1.2.tar.xz &&

  23. xz -d gmp-6.0.0a.tar.xz

  24. tar -xvf mpfr-3.1.2.tar &&
  25. tar -xvf gmp-6.0.0a.tar

  26. rm -f *.tar.gz


  27. #create directory for each binary executable files store
  28. #/usr/local/ is preferred optional main directory branch

  29. mkdir $GMP_HOME &&
  30. mkdir $MPFR_HOME &&
  31. mkdir $MPC_HOME &&
  32. mkdir $GCC_HOME



  33. #here MPFR depends on GMP library , and MPC depends on
  34. #both GMP and MPFR , so we install GMP first

  35.     #set gmp binary file installation path name and other compile info
  36.     /Xshell/gmp-6.0.0/configure --prefix=$GMP_HOME
  37.      
  38.     #run make file and make install
  39.     cd /Xshell/gmp-6.0.0 && make && make install
  40. #-------------------------------------

  41.     #set mpc binary file installation path name and other compile options
  42.     /Xshell/mpfr/configure --prefix=$MPFR_HOME --with-gmp=$GMP_HOME

  43.     #run make file and make install command
  44.     cd /Xshell/mpfr-1.0.3 && make && make install
  45. #-------------------------------------

  46.     #set MPFR binary file installation path name and other dependency options
  47.     /Xshell/mpc/configure --prefix=$MPC_HOME --with-gmp=$GMP_HOME --with-mpfr=$MPFR_HOME
  48.   
  49.     #run make file and make install command
  50.     cd /Xshell/mpc-3.1.2 && make && make install
  51. #-------------------------------------

  52. echo 'dependency libraries are installed properly , now let set , compile and install gcc '

  53. # here we begin to install gcc library

  54. # first and most important is to add new installed three libraries'
  55. # path to the /etc/profile , and update /etc/profile this file

  56.    echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GMP_HOME:$MPFR_HOME:$MPC_HOME" | tee -a /etc/profile

  57.    source /etc/profile

  58. # change directory to gcc package downloaded path
  59.     
  60. #-------------------------------------
  61.     #set binary executable file path

  62.         /Xshell/gcc-4.8.2/configure --prefix=$GCC_HOME -enable-threads=posix \
  63.     -disable-checking -disable-multilib -enable-languages=c,c++ \
  64.         --with-gmp=$GMP_HOME --with-mpfr=$MPFR_HOME --with-mpc=$MPC_HOME
  65.     

  66.      echo "now we make and make install gcc , patience wait for almost 1 hour"

  67.     #make and make install
  68.      cd /Xshell/gcc-4.8.2 && make && make install

  69.     #update the soft-link gcc and g++ in directory /usr/bin/
  70.     mv /usr/bin/gcc /usr/bin/gcc47
  71.     mv /usr/bin/g++ /usr/bin/gpp47
  72.     
  73.     ln -s $GCC_HOME/bin/gcc /usr/bin/gcc
  74.     ln -s $GCC_HOME/bin/g++ /usr/bin/g++


  75. #-------------------------------------

  76. #finally , check whether gcc is updated successfully
  77. echo 'here we check version of the current gcc
  78. g++ -v
运行之记得前要 chmod 755 一下

end
阅读(1517) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

夏目玲子2015-06-14 21:44:26

[我是烂脚本]:怪我咯!

回复 | 举报

夏目玲子2015-06-14 18:52:36

写脚本的好处是,记得牢,因为记录操作命令,只要一次执行正确得到结果就可以了。
但是写脚本却需要反反复复把整个流程走上好几遍,才能总结出一个可以正确运行的脚本(中途会遇到很多的错误分支).