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/20170923212414.16744-10-romain.naour@gmail.com/ 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

8. 报错:

/home/openailab/Downloads/test/gcc-4.9.4-build-temp/./gcc/xgcc: /home/openailab/Downloads/test/gcc-4.9.4-build-temp/aarch64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /home/openailab/Downloads/test/gcc-4.9.4-build-temp/./gcc/xgcc)
make[3]: *** [Makefile:942: libgcc_s.so] Error 1

这个错误网上找不到解决方法,这个尝试暂停。

参考:

https://www.cnblogs.com/succeed/p/6204438.html https://www.cnblogs.com/alianbog/p/12498915.html https://developer.aliyun.com/article/90390 https://blog.csdn.net/llh_1178/article/details/79329250 https://www.theobroma-systems.com/rk3399-q7-user-manual/04-software.html https://www.jianshu.com/p/0caef3ce8e06 https://gcc.gnu.org/install/ https://www.cnblogs.com/uestc-mm/p/7511063.html https://blog.csdn.net/xiexievv/article/details/50620170 https://zhuanlan.zhihu.com/p/107133028 https://www.jianshu.com/p/fc162672fae2 https://blog.csdn.net/u013946356/article/details/83106133

标签: build

添加新评论