最近在编译的时候遇到一个问题,同事那边用aarch-gcc v7.3编译是正常的,但是我这边编译的时候用aarch-gcc v5.4就会报错,据说是因为新版本的aarch-gcc会优化代码空间,我又不想升级到最新的ubuntu,于是就有了升级aarch-gcc和gcc的需求,下面是简单的记录
由于我们是用编译源码的方式安装新版的gcc,所以源码时必需的。总的来说,现在比较主流的gcc-compile-toolchain有两种:
1, Code Sourcery ARM Linux toolchain
由于mentor这套交叉编译工具链需要登录才能下载,所以此处一笔带过,不详细展开
https://www.mentor.com/embedded-software/sourcery-tools-services/
2, Linaro ARM Linux
https://releases.linaro.org/components/toolchain/gcc-linaro/
而对于升级这件事来说也有两种方式,
1 直接下载官方的二进制文件,添加好环境变量来用
2 源码编译的方式
下载二进制文件的方式比较简单,从
http://releases.linaro.org/components/toolchain/binaries/
下载,export路径就行了
export PATH=$YOUR_DIR:$PATH
编译源码就比较复杂了,主要分为configure、make、make install 三步,下面详细来介绍
0 下载源码、
https://releases.linaro.org/components/toolchain/gcc-linaro/
我下的是最新的latest-7版本
1 configure
./configure --enable-checking=release --enable-languages=c,c++ \
--disable-multilib --prefix=/usr/gcc_linaro --target=aarch64-linux
(注意这里一定建议加prefix选项,指定make install的位置!!!)
2 make & make install
make -j4 && sudo make install
可能遇到的问题
Q1:configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Q2:error: cannot compute suffix of object files: cannot compile
A1 & A2:
下面就有错误提示
checking for suffix of object files... configure: error: in `/home/xxx/gcc-linaro-7.5-2019.12/aarch64-linux/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
打开 ftp://gcc.gnu.org/pub/gcc/infrastructure/ 找到这几个
解压然后按下面的步骤
./configure
make
make check (据说如果make不报错的话make check的错误就可以忽略。。。)
sudo make install
安装完上面这三个工具以后应该就可以正常安装上面的aarch-gcc了。
Q3:/usr/include/linux/errno.h:1:10: fatal error: asm/errno.h: No such file or directory
A3:
sudo ln -s /usr/include/asm-generic /usr/include/asm
继续make
Q4:gcc -v 还是原来的版本
A4:需要更新环境变量
因为现在旧的shell用的还是之前那一套环境变量之类的,export一下 gcc -v就可以了
问题4:configure: error: cannot compute suffix of object files: cannot compile
解决:
这是因为系统找不到上面安装的gmp、mpc、mpfr等支持库
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
(未解决)
下面开始安装aarch64-gcc
还是gcc的这个目录,但是这次我们./configure的时候要指定不同的target
$ mkdir build-bin
$ cd build-bin
$ ./configure --target=aarch64-linux --prefix=/usr/gcc_linaro --disable-multilib
$ make -j4
$ make install