升級GCC之困難重重版

升級GCC步驟:gmp->mpfr->mpc->GCC
環境 VM:VMware Player 5.0
OS:CentOS(6.5 2.6.32-431.el6.i686)
GCC:4.4.7 --> 4.8.2

GCC載點:ftp://gnu.mirror.iweb.com/gcc/
gmp官網:http://gmplib.org/
mpfr官網:http://www.mpfr.org/
mpc載點:ftp://ftp.gnu.org/gnu/mpc/

安裝gmp、mpfr、mpc

# wget https://gmplib.org/download/gmp/gmp-5.1.3.tar.lz
# tar xf gmp-5.1.3.tar.lz
# yum install -y lzip
# cd /data/src/gmp-5.1.3
# ./configure --prefix=/data/src/gmp-5.1.3
# make -j && make check && make install

# wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.gz
# tar zxf mpfr-3.1.2.tar.gz
# cd /data/src/mpfr-3.1.2
# ./configure --prefix=/data/src/mpfr-3.1.2 --with-gmp=/data/src/gmp-5.1.3
# make -j && make check && make install

# wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz
# tar zxf mpc-1.0.2.tar.gz
# cd mpc-1.0.2
# ./configure --prefix=/data/src/mpc-1.0.2 --with-mpfr=/data/src/mpfr-3.1.2 --with-gmp=/data/src/gmp-5.1.3
# make -j && make check && make install

# vim /etc/ld.so.conf
  /data/src/gmp-5.1.3/lib
  /data/src/mpfr-3.1.2/lib
  /data/src/mpc-1.0.2/lib
# ldconfig

//環境變數LD_LIBRARY_PATH及LD_RUN_PATH設定,避免GCC編譯時發生錯誤。
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/src/mpc-1.0.2/lib:/data/src/mpc-1.0.2/lib:/data/src/mpc-1.0.2/lib
# export LD_RUN_PATH=$LD_LIBRARY_PATH:/data/src/mpc-1.0.2/lib:/data/src/mpc-1.0.2/lib:/data/src/mpc-1.0.2/lib

安裝GCC # yum install -y gcc-c++
# curl -R -O ftp://gnu.mirror.iweb.com/gcc/gcc-4.8.2/gcc-4.8.2.tar.gz
# mkdir build_gcc482
# cd build_gcc482
# ../gcc-4.8.2/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/data/src/gmp-5.1.3 --with-mpfr=/data/src/mpfr-3.1.2 --with-mpc=/data/src/mpc-1.0.1
  ...略
  checking for the correct version of gmp.h... yes
  checking for the correct version of mpfr.h... yes
  checking for the correct version of mpc.h... no
  configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
  //找不到mpc.h的錯誤訊息,原來是我路徑打錯了。

  Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
  their locations. Source code for these libraries can be found at
  their respective hosting sites as well as at
  ftp://gcc.gnu.org/pub/gcc/infrastructure/. See also
  http://gcc.gnu.org/install/prerequisites.html for additional info. If
  you obtained GMP, MPFR and/or MPC from a vendor distribution package,
  make sure that you have installed both the libraries and the header
  files. They may be located in separate packages.
# ../gcc-4.8.2/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib --with-gmp=/data/src/gmp-5.1.3 --with-mpfr=/data/src/mpfr-3.1.2 --with-mpc=/data/src/mpc-1.0.2
# make && make install
# gcc --version   gcc (GCC) 4.8.2
  Copyright (C) 2013 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions. There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

測試

# vim helloworld.c
  #include
  int main(void){
  printf("hello world. \n");
  return 0;
  }
# gcc helloworld.c
# ls
  a.out helloworld.c
# ./a.out
  hello world.

沒有留言:

張貼留言