嵌入式linux 开发离不开交叉编译,所以搭建交叉编译环境是必须的。一般build平台(编译该软件所使用的平台)选择linux,host平台为ARM(该软件将运行的平台),我的build的主机是一台安装了ubuntn18.04的笔记本电脑,有条件的当然也可以选择云服务器来作为编译主机。
1 交叉编译工具链下载
RIoTboard官方提供的交叉编译工具链为fsl-linaro-toolchain,可以通过我在RIoTBoard开发板系列笔记(一)— 环境搭建里分享的百度云资源下载,不过下载太慢。官方针对该款开发版建立的github仓库,里面有系统源码、编译工具链等工具,地址为:
https://github.com/embest-tech
通过git下载交叉编译工具链下载:
git clone https://github.com/embest-tech/fsl-linaro-toolchain
2 交叉编译工具链配置安装
将交叉编译工具链下载复制到usr目录:
sudo cp -rf fsl-linaro-toolchain/ /usr/local/complie_tool/
这样工具链就位于以下目录了。
/usr/local/complie_tool/fsl-linaro-toolchain
更改执行权限
sudo chmod 777 fsl-linaro-toolchain/
配置环境变量,把交叉编译工具链的路径添加到环境变量PATH中去,就可以在任何目录下使用这些工具。
执行以下命令,打开profile文件
sudo vim /etc/profile
在profile中最后一行添加:
ARCH=arm
CROSS_COMPILE=/usr/local/complie_tool/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-
PATH=$PATH:/usr/local/complie_tool/fsl-linaro-toolchain/bin
export PATH ARCH CROSS_COMPILE
执行如下命令,使环境变量生效。
source /etc/profile
运行如下命令测试是否安装配置成功:
arm-linux-gcc -v
运行后报了错误:
bash: /usr/local/complie_tool/fsl-linaro-toolchain/bin/arm-linux-gcc: No such file or directory
出现该错误需要安装32位兼容库,执行以下命令:
sudo apt-get install lib32z1
然后再执行:
arm-linux-gcc -v
可以看到已经显示了version信息,证明已经安装成功了。