2020年5月22日 星期五

Build GCC G++ 10.1.0 Toolchain on CentOS 7.5

Build GCC G++ 10.1.0 Toolchain on CentOS 7.5


參考來源:



# 我是以 root 登入系統
# 登入後,先更新系統

> yum -y update


# 安裝 & 更新目前的 gcc 及 其他可能會用到的套件

> yum -y install gcc gcc-c++

> yum -y install tar wget make git openssl-devel bzip2 libcurl-devel autoconf automake libtool 

# 安裝 zlib & 開發套件

> yum -y install zlib zlib-devel

#安裝 xz 壓縮工具

> yum install xz -y


修改FD_SETSIZE(非必要)

(在寫socket programming時會用select 搭配 fd_set 來偵測 file descriptor 是否可讀寫
 但Linux 系統預設的 fd_set size 只有 1024,若同時間處理的 fd 超過 1024 就會出問題
 修改下面這兩個檔案,重新 build application 時就會引用到新的 define 值)

vim /usr/include/linux/posix_types.h
   #define __FD_SETSIZE    1024 => 改65535

vim /usr/include/bits/typesizes.h
   #define __FD_SETSIZE    1024 => 改65535

或使用Sed 修改
sed -i 's/\(FD_SETSIZE\s\+\)\([0-9]\+\)/\165535/g' /usr/include/linux/posix_types.h
sed -i 's/\(FD_SETSIZE\s\+\)\([0-9]\+\)/\165535/g' /usr/include/bits/typesizes.h

#來源:

https://ftp.gnu.org/gnu/gcc/gcc-10.1.0/gcc-10.1.0.tar.xz
ftp://ftp.gnu.org/gnu/gcc/gcc-10.1.0/gcc-10.1.0.tar.xz
https://mirror.ossplanet.net/gnu/gcc/gcc-10.1.0/gcc-10.1.0.tar.gz
註:要確定抓下來的檔案沒問題,可以正確解壓,若有問題可以網上搜尋其他的載點

#抓取 gcc 10.1.0 source

> wget ftp://ftp.gnu.org/gnu/gcc/gcc-10.1.0/gcc-10.1.0.tar.xz

#解壓縮 gcc

> tar -Jxvf gcc-10.1.0.tar.xz
> cd gcc-10.1.0
> case $(uname -m) in
  x86_64)
    sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64
  ;;
esac


# 下載Build時需要的檔案

> ./contrib/download_prerequisites

2020-05-21 18:23:31 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840/2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2020-05-21 18:23:40 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284/1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2020-05-21 18:23:41 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925/669925] -> "./mpc-1.0.3.tar.gz" [1]
2020-05-21 18:23:47 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291/1658291] -> "./isl-0.18.tar.bz2" [1]
gmp-6.1.0.tar.bz2: 正確
mpfr-3.1.4.tar.bz2: 正確
mpc-1.0.3.tar.gz: 正確
isl-0.18.tar.bz2: 正確
All prerequisites downloaded successfully.


# 建立一個用來編譯GCC的資料夾

> mkdir build 
> cd build


# 依系統環境設置產生編譯 GCC 的 Makefile

> ../configure -v --build=x86_64-linux-gnu \
                --host=x86_64-linux-gnu \
                --target=x86_64-linux-gnu \
                --enable-checking=release \
                --enable-languages=c,c++ \
                --disable-multilib \
                --program-suffix=-10.1 \
                --prefix=/usr/local/gcc-10.1.0

# 或是這個設置
> ../configure --disable-multilib --enable-languages=c,c++

# 開始編譯

> make
or
> make -j4


# 等待...漫長的等待...原來是件好事...因為代表沒有出現錯誤...而中止......

# 但現實往往總是不如人願

In file included from ../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:167:
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:1083:17: error: ‘__kernel_fd_set’ was not declared in this scope; did you mean ‘__kernel_off_t’?
 1083 | CHECK_TYPE_SIZE(__kernel_fd_set);
      |                 ^~~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_internal_defs.h:342:65: note: in definition of macro ‘IMPL_COMPILER_ASSERT’
  342 |     typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
      |                                                                 ^~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h:1426:3: note: in expansion of macro ‘COMPILER_CHECK’
 1426 |   COMPILER_CHECK(sizeof(__sanitizer_##TYPE) == sizeof(TYPE))
      |   ^~~~~~~~~~~~~~
../../../../libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp:1083:1: note: in expansion of macro ‘CHECK_TYPE_SIZE’
 1083 | CHECK_TYPE_SIZE(__kernel_fd_set);
      | ^~~~~~~~~~~~~~~
make[4]: *** [sanitizer_platform_limits_posix.lo] Error 1
make[4]: Leaving directory `/root/gcc-10.1.0/build/x86_64-linux-gnu/libsanitizer/sanitizer_common'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/root/gcc-10.1.0/build/x86_64-linux-gnu/libsanitizer'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/gcc-10.1.0/build/x86_64-linux-gnu/libsanitizer'
make[1]: *** [all-target-libsanitizer] Error 2
make[1]: Leaving directory `/root/gcc-10.1.0/build'
make: *** [all] Error 2

# 所以,目前還在爬文看看怎麼解決這個錯誤



# 將編好的程式安裝到系統中

> make install