# Crosstool-NG update GCC4.5.4 to GCC4.8.5 開發筆記
## Installation
- Crosstool-NG Version: **v1.22**
Follow https://crosstool-ng.github.io/docs/install/
```
git clone https://github.com/crosstool-ng/crosstool-ng
./bootstrap
./configure --prefix=/some/place
make
make install
```
## Use ct_ng
- Common command
```
#clean
ct-ng clean
#build
ct-ng build
#menuconfig
ct-ng menuconfig
```
- Output
If success, default toolchain path is `~/{HOME}/x-tools`
## menuconfig Settings
- AST menuconfig is located at `~/sdk/crosstool/aspeedv6_4.8.5.config`
- `CT_LOCAL_TARBALLS_DIR`
- 可預先將相關的tarball存到此路徑,crosstool會先從這邊找,如果找不到才會從網路抓
- crosstool從網路抓的來源會根據`~/crosstool/lib/scripts/companion_libs/*.sh`腳本內的ftp網址 or git repo去抓,注意如果是用舊版本的crosstool (e.g. v1.22),很有可能會是deprecated address,可以手動先抓好放到此路徑
- `CT_ARCH_CPU`
- for AST1220, use `arm1176jzf-s`
- `CT_ARCH_FPU`
- FPU option, for AST1220, use `vfp`
- `CT_ARCH_SUFFIX`
- build出來的naming會有arm{SUFFIX}
- `CT_CC_GCC_VERSION`
- target gcc verison: 4.8.5
- `CT_CC_LANG_CXX`
- Enable building a C++ compiler. 開了才會有`*g++`可以用
- other companion lib version config
```
CT_KERNEL_VERSION: 4.3
CT_BINUTILS_VERSION: 2.25.1
CT_LIBC_VERSION: 2.22
CT_GDB_VERSION: 7.10
CT_LIBICONV_VERSION: 1.14
CT_GETTEXT_VERSION: 0.19.6
CT_GMP_VERSION: 6.0.0a
CT_MPFR_VERSION: 3.1.3
CT_CLOOG_VERSION: 0.18.4
CT_ISL_VERSION: 0.14
CT_MPC_VERSION: 1.0.3
CT_EXPAT_VERSION: 2.1.0
CT_NCURSES_VERSION: 6.0
```
## 採到的坑
- gmp version too old, but config already set to v6.0.0a?
```
checking for the GMP library version 4.1.3 or above... no
configure: error: Cannot find GMP version 4.1.3 or higher.
GMP is the GNU Multi-Precision library:
see http://www.swox.com/gmp/ for more information.
When compiling the GMP library, do not forget to enable the C++ interface:
add --enable-cxx to the configuration options.
```
解決方法:
**sudo apt-get install libgmp3-dev**
---
- glibc compile error
```
dl-openat64.c:26:1: error: 'openat64' defined as variadic function without prototype [-Werror]
```
解決方法:
**apply patch below**
https://blog.csdn.net/gx1313113/article/details/101154742
---
- install final gcc compiler error
```
error: 'const char* libc_name_p(const char*, unsigned int)' redeclared inline with 'gnu_inline' attribute
```
解決方法:
**check ubuntu gcc version, sometimes this happens when target gcc version older than installed gcc**
https://blog.csdn.net/agave7/article/details/88865757
> How to install different gcc version on ubuntu?
> ```
> sudo apt install gcc-4.8
> sudo apt install g++-4.8
> ```
> Check installed gcc version
> ```
> ls -l /usr/bin/x86_64*
> ```
> Set priority (gcc-4.8 priority 90 > gcc-6, hence use gcc-4.8)
> ```
> sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 90 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.8
> sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 80 --slave /usr/bin/g++ g++ /usr/bin/g++-6 --slave /usr/bin/gcov gcov /usr/bin/gcov-6
> ```
> Check current used gcc version
> ```
> gcc-v
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
> Target: x86_64-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.5-4ubuntu8' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
> Thread model: posix
> gcc version 4.8.5 (Ubuntu 4.8.5-4ubuntu8)
> ```