2020年6月18日 星期四

CentOS 6上編譯GCC 4.8.5

CentOS 6上面預設的編譯器是GCC-4.4.7,自行編譯一套GCC-4.8.5的步驟如下:
  1. 安裝GMP,這邊選4.3.2版
  2. 安裝MPFR,這邊選2.4.2版
  3. 安裝MPC,這裡選0.8.1版
  4. 安裝ISL,這裡選0.14版
  5. 下載GCC-4.8.5原始碼,設定編譯與安裝

下面的指令前面的錢字號是提示符號,前面沒有錢字號的則是螢幕輸出。最終的目的是要將GCC-4.8.5相關的程式,通通都安裝到 /Software/gcc/4.8.5/ 這個資料夾下面

步驟1. GNU Multiple Precision Arithmetic Library GMP-4.3.2安裝
$ cd /tmp
$ wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
$ md5sum gmp-4.3.2.tar.bz2
dd60683d7057917e34630b4a787932e8  gmp-4.3.2.tar.bz2

$ tar jxvf /tmp/gmp-4.3.2.tar.bz2 && cd gmp-4.3.2
$ ./configure --prefix=/Software/gcc/4.8.5
$ make -j 32 >make.log 2>&1 &
$ make check
$ make install && echo $?


步驟2:GNU Multiple-precision floating-point rounding library MPFR-2.4.2安裝
$ cd /tmp
$ wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
$ md5sum mpfr-2.4.2.tar.bz2
89e59fe665e2b3ad44a6789f40b059a0  mpfr-2.4.2.tar.bz2

$ tar jxf /tmp/mpfr-2.4.2.tar.bz2 && cd mpfr-2.4.2
$ ./configure --prefix=/Software/gcc/4.8.5 \
              --with-gmp=/Software/gcc/4.8.5
$ make -j 32 >make.log 2>&1 &
$ make check
$ make install && echo $?


步驟3:GNU Multiple-precision C library MPC-0.8.10安裝
$ cd /tmp
$ wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
$ md5sum mpc-0.8.1.tar.gz
5b34aa804d514cc295414a963aedb6bf  mpc-0.8.1.tar.gz

$ tar zxf /tmp/mpc-0.8.1.tar.gz && cd mpc-0.8.1
$ ./configure --prefix=/Software/gcc/4.8.5 \
              --with-gmp=/Software/gcc/4.8.5 \
              --with-mpfr=/Software/gcc/4.8.5
$ make -j 32 >make.log 2>&1 &
$ make check
$ make install && echo $?


步驟4:ISL-0.14安裝
$ cd /tmp
$ wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.14.tar.bz2
$ md5sum isl-0.14.tar.bz2
acd347243fca5609e3df37dba47fd0bb  isl-0.14.tar.bz2

$ tar jxf /tmp/isl-0.14.tar.bz2 && cd isl-0.14
$ ./configure --prefix=/Software/gcc/4.8.5 \
              --with-gmp-prefix=/Software/gcc/4.8.5 
$ time make -j 32 >make.log 2>&1 &
$ make check
$ make install & echo $?
這邊要特別注意是--with-gmp-prefix而不是--with-gmp喔~


步驟5:GCC-4.8.5安裝
$ cd /tmp
$ wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.8.5/gcc-4.8.5.tar.gz
$ md5sum gcc-4.8.5.tar.gz
bfe56e74d31d25009c8fb55fd3ca7e01  gcc-4.8.5.tar.gz
$ shasum -a 512 gcc-4.8.5.tar.gz
a012e06f975f82c053a9671483173bceeff4d9efc6a6d6e51304ef2a09a86c40f8088e23465f1d729276a34031bb1655cacef9f8a960f6206a3382dd0dc431e9  gcc-4.8.5.tar.gz


$ tar zxf gcc-4.8.5.tar.gz && cd gcc-4.8.5/
$ ./configure --prefix=/Software/gcc/4.8.5 \
              --with-isl=/Software/gcc/4.8.5 \
              --with-mpc=/Software/gcc/4.8.5 \
              --with-mpfr=/Software/gcc/4.8.5 \
              --with-gmp=/Software/gcc/4.8.5 \
              --disable-multilib
$ export LD_LIBRARY_PATH=/Software/gcc/4.8.5/lib:$LD_LIBRARY_PATH 
$ time make -j 32 >make.log 2>&1 &
$ make install
用32核心編譯約莫花費了25分鐘,這邊使用--disable-multilib是因為出現gnu/stubs-32.h: No such file or directory這個錯誤訊息。下面是編譯出來的GCC-4.8.5的一些資訊。整個安裝完的大小約莫是800MB。
$ du -h /Software/gcc/4.8.5/ --max-depth=1
30M     /Software/gcc/4.8.5/share
20M     /Software/gcc/4.8.5/lib
26M     /Software/gcc/4.8.5/include
455M    /Software/gcc/4.8.5/libexec
20M     /Software/gcc/4.8.5/bin
245M    /Software/gcc/4.8.5/lib64
794M    /Software/gcc/4.8.5/

$ /Software/gcc/4.8.5/bin/gcc --version
gcc (GCC) 4.8.5
Copyright (C) 2015 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.

$ ldd /Software/gcc/4.8.5/bin/gcc
        linux-vdso.so.1 =>  (0x00007fff62565000)
        libm.so.6 => /lib64/libm.so.6 (0x0000003a48200000)
        libc.so.6 => /lib64/libc.so.6 (0x0000003a47600000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003a47200000)


參考資料

_EOF_

沒有留言:

張貼留言