1. 程式人生 > 實用技巧 >fedora rk3399 gcc 4.9.3

fedora rk3399 gcc 4.9.3

1. 下載 gcc 4.9.3 的原始碼。

http://ftp.gnu.org/gnu/gcc/gcc-4.9.3/ 或者國內的交大 https://mirrors.sjtug.sjtu.edu.cn/gnu/gcc/gcc-4.9.3/

2. 解壓 gcc 原始碼,然後從 gcc-4.9.3/contrib/download_prerequisites 這個檔案中讀取需要依賴的包。下載相應的依賴包。

# Necessary to build GCC.
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1
  ISL=isl-0.12.2
  CLOOG=cloog-0.18.1

https://mirrors.sjtug.sjtu.edu.cn/gnu/

可以下載 gcc, mpfr, gmp
https://sourceforge.net/projects/d2718c/ 可以下載好幾個東西,但是速度是個問題。
https://src.fedoraproject.org/lookaside/extras/gcc/isl-0.12.2.tar.bz2 可以下載 isl ,速度還可以。

3. 把第二部的壓縮包解壓到 gcc 原始碼目錄下,然後 ln -sf xxx-xxx xxx,建立這幾個包的軟連線。如果不想這麼麻煩,並且網路很好的話,直接在上一步執行 download_prerequisites 也可以。

4.

cd ..
mkdir gcc-4.9.3-build-temp
cd gcc-4.9.3-build-temp

5. 根據原來機器的 gcc -v 獲得相應的 config 選項,然後配置新的選項,做成指令碼進行執行。

6. config 的時候,報錯:

GNAT is required to build ada
這個因為不需要 ada,所以直接在 language 選項裡面去掉 ada 就可以了。
參考: http://gcc.1065356.n8.nabble.com/GNAT-is-required-to-build-ada-td692409.html
https://github.com/spack/spack/issues/15867
https://github.com/owent-utils/bash-shell/issues/2

6. make -jX 之後,報錯:

In file included from ../../gcc-4.9.3/gcc/cp/except.c:1013:cfns.gperf:101:1: error: ‘const char* libc_name_p(const char*, unsigned int)’ redeclared inline with ‘gnu_inline’ attribute

這個使用 4.9.4 版本就可以了。
參考: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=831142
https://github.com/jens-maus/RaspberryMatic/issues/28

7. 報錯:

/md-unwind-support.h: In function ‘aarch64_fallback_frame_state’:error: field ‘uc’ has incomplete typestruct ucontext uc;
這個是因為 glibc 有更新導致的,需要修改 gcc-4.9.4/libgcc/config/XXX/linux_unwind.h 這個標頭檔案,把 struct ucontext uc; 去掉,換成 ucontext_t uc; 因為 /usr/include/sys/ucontext.h 裡面是這個定義。所以要按照新的 libc 來修改一下。當然也可以打補丁代替手動修改。

參考: https://stackoverflow.com/questions/46999900/how-to-compile-gcc-6-4-0-with-gcc-7-2-in-archlinux
https://blog.csdn.net/XCCCCZ/article/details/80958414
https://patchwork.ozlabs.org/project/buildroot/patch/[email protected]/
http://lists.busybox.net/pipermail/buildroot/2017-September/202526.html
https://blog.csdn.net/wang805447391/article/details/83380302
https://unix.stackexchange.com/questions/566650/how-do-i-compile-gcc-5-from-source
https://stackoverflow.com/questions/52498431/compile-gcc6-4-0-using-gcc8-1-1
https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=libgcc/config/aarch64/linux-unwind.h;h=d46d5f53be379ec2dbc9a5ba95d51e22c1d52c2f;hp=d5d6980442fd47b1f1e499e99cb25b5fffbdbeb3;hb=883312dc79806f513275b72502231c751c14ff72;hpb=601d22f69093aa98dcf9593bc138da7ba8281e05
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=883312dc79806f513275b72502231c751c14ff72