Android车机DIY开发之学习篇(七)NDK交叉工具构建
1.ubuntu安装GCC
sudo apt-get update
sudo apt-get install gcc g++
sudo gcc --version
sudo g++ --version
2.测试GCC
VSCODE中新建Hello.c编译
#include <stdio.h>
int main(void)
{
printf(“Hello, this is a program compiled by ndk-cross-compiler!\n”);
}
alientek@alientek:~/VSCODESOURCE$ gcc Hello.c -o hello
alientek@alientek:~/VSCODESOURCE$ ./hello
Hello, this is a program compiled by ndk-cross-compiler!
alientek@alientek:~/VSCODESOURCE$
此程序无法应用到ARM开发板上
3.安装android-ndk-r17c交叉编译工具,使可以运行到android系统上
下载后解压文件进入build/tools执行以下命令
./make-standalone-toolchain.sh --install-dir=/tmp/my-android-toolchain/ --toolchain=aarch64-linux-android
在Bashrc中增加
export PATH=$PATH:/tmp/my-android-toolchain/bin
export CC=“aarch64-linux-android-gcc”
export CXX=“aarch64-linux-android-g++”
使生效
source ~/.bashrc
4. 编译测试
aarch64-linux-android-gcc Hello.c -o hello
file *
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, not stripped