aarch64开发板交叉编译工具的使用 -arm64
背景:因为公司开发板是aarch64,所以需要安装交叉编译工具aarch64-linux-gnu-gcc/g++
关于aarch64-linux-gnu-gcc/g++介绍:
The GNU Compiler Collection - cross compiler for ARM64 target.
aarch64-linux-gnu-gcc/g++ 是一个交叉编译工具链,可以在其他架构的系统中,编译安装 64 位 arm
架构的程序。常用在嵌入式代码的移植中。aarch64-linux-gnu-gcc/g++ 是由非盈利组织Lingaro 基于 GCC/G++
推出的 ARM 交叉编译工具。可用于交叉编译 ARMv8 64 位目标中的裸机程序、u-boot、Linux
kernel、filesystem 和 App 应用程序。aarch64-linux-gnu-gcc/g++ 交叉编译器必须安装在 64
位主机上,才能编译目标代码。
# 查看可以安装的版本
apt-cache search aarch64
# 选择可以安装的版本进行安装
# 此处选择gcc-5-aarch64-linux-gnu进行安装
sudo apt-get install gcc-5-aarch64-linux-gnu
# 安装依赖
sudo apt --fix-broken install
# 安装一个没有版本号的gcc
sudo apt-get install gcc-aarch64-linux-gnu
# 查看版本
aarch64-linux-gnu-gcc -v
编写测试文件:
#include<stdio.h>
int main()
{
printf("hello world!\n");
return 0;
}
aarch64-linux-gnu-gcc test.c -o test
# 将生成的可执行文件放到嵌入式板子上运行
./test # 若显示hello world!表示成功
注:查看可执行文件类型:
DESKTOP-9JE80U8:~$ readelf -h test
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: AArch64
Version: 0x1
Entry point address: 0x660
Start of program headers: 64 (bytes into file)
Start of section headers: 7504 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 64 (bytes)
Number of section headers: 28
Section header string table index: 27
Machine: AArch64
本文链接:http://it72.com/12793.htm