查看 GLIBC 版本
首先确认目标平台支持的 GLIBC 版本,例如:
target:~$ strings /lib/*gnu*/libm.so.6 | grep GLIBC
GLIBC_2.17
GLIBC_2.18
GLIBC_2.23
GLIBC_2.24
GLIBC_2.25
GLIBC_2.27
GLIBC_2.28
GLIBC_2.29
GLIBC_2.31
GLIBC_PRIVATE
可以看出,支持的 GLIBC 版本有 2.17、2.18、2.23-2.25、2.27-2.29、2.31,知道支持版本后就可以自行编译或下载预编译好的 toolchain。
安装交叉编译工工具链
预编译的 toolchain 可以在 linaro 或 arm 官网下载。
这里去 linaro 官网下载 glibc 2.25 版本的工具链, https://releases.linaro.org/components/toolchain/binaries/latest-7/aarch64-linux-gnu/gcc-linaro-7.5.0-2019.12-i686-mingw32_aarch64-linux-gnu.tar.xz
解压在 Windows 系统的任意路径下,解压后进入 bin 目录,找到 xxx-gnu-gcc.exe 可执行文件,复制全路径备用
跨平台编译测试
这里使用简单的 helloworld 程序测试
创建 main.c 文件,输入如下内容:
#include <stdio.h>
int main()
{
printf("Hello World !\n");
return 0;
}
保存后,在 main.c 文件所在路径下打开命令提示行,执行如下命令编译 C 源代码。
PS D:\helloworld> D:\sdk\gnu-toolchain\gcc-linaro-7.5.0-2019.12-i686-mingw32_aarch64-linux-gnu\bin\aarch64-linux-gnu-gcc.exe -o .\helloworld main.c
编译成功结束后,会在当前路径下生成目标平台的可执行文件 helloworld
将其复制到目标平台上执行即可看到运行结果
target:~$ ./helloworld
Hello World !
至此,就完成了交叉编译工具链的基本验证
版权属于:wshon
本文链接:https://blog.wshon.com/2022/07/01-toolchain.html
转载时须注明出处及本声明
最新回复