【安装编译工具链】
1、下载到的SDK工具包中有两个文件:gcc_linaro_7.3.tar、gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar。
将这两个安装包上传到ubuntu虚拟机中。
2、新建目录/tool
sudo mkdir -p /tool
3、解压两个文件到/tool目录下面
tar -xvf gcc_linaro_7.3.tar.gz -C /tool
tar -xvf gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz
【注】在软件开发指南中,他只说解压一个文件,这样在加载SDK时报错。
4、编写env.sh,为了方便加载环境,所以在编译时需要加载SDK的环境。
编写如下:
export PATH=$PATH:/tool/gcc_linaro/gcc-arm-none-eabi-7.3.1/bin:/tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-elf/bin:/tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu- export PREFIX=aarch64-linux-gnu- export AS=aarch64-linux-gnu-as
export LD=aarch64-linux-gnu-ld
export CC=aarch64-linux-gnu-gcc
export AR=aarch64-linux-gnu-ar
export NM=aarch64-linux-gnu-nm
export STRIP=aarch64-linux-gnu-strip
export OBJCOPY=aarch64-linux-gnu-objcopy
export OBJDUMP=aarch64-linux-gnu-objdump
【注】在复制开发板指南时一定要注意消除空格,要不也会报找不到文件的错误。
5、设置环境变量,并测试安装是否完成。
lu@lu-virtual-machine:/home/YD9X$ source env.sh
lu@lu-virtual-machine:/home/YD9X$ aarch64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/tool/gcc_linaro/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/../libexec/gcc/aarch64-linux-gnu/7.3.1/lto-wrapper
Target: aarch64-linux-gnu
Configured with: '/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/snapshots/gcc.git~linaro-7.3-2018.05/configure' SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libmudflap --enable-lto --enable-shared --without-included-gettext --enable-nls --with-system-zlib --disable-sjlj-exceptions --enable-gnu-unique-object --enable-linker-build-id --disable-libstdcxx-pch --enable-c99 --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-arch=armv8-a --enable-threads=posix --enable-multiarch --enable-libstdcxx-time=yes --enable-gnu-indirect-function --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/sysroots/aarch64-linux-gnu --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu/aarch64-linux-gnu/libc --enable-checking=release --disable-bootstrap --enable-languages=c,c++,fortran,lto --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=aarch64-linux-gnu --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701] (Linaro GCC 7.3-2018.05)
这里成功的看到了gcc version 7.3.1,说明安装编译工具成功。
【测试hello world】
1、创建hello.c内存如下:
#include <stdio.h>
int main(void)
{
printf("hello YD9X");
return 0;
}
2、使用aarch64-linux-gnu-gcc来对hello.c进行编译,输出hello
lu@lu-virtual-machine:/home/YD9X$ aarch64-linux-gnu-gcc hello.c -o hello
lu@lu-virtual-machine:/home/YD9X$
3、将hello scp 给开发板:
lu@lu-virtual-machine:/home/YD9X$ scp hello root@192.168.3.169:/home
hello 100% 14KB 1.8MB/s 00:00
lu@lu-virtual-machine:/home/YD9X$
4、在开发板上给予hello的可执权限,执行程序,效果如下:
达到如期的目的。
【小结】
在拿到资料后,安装编译工具是一个最开始的起点,非常重要,说明文档还有一些写得不够详细的地方,如果没有丰富的经验,将遇到很大的难题。