交叉编译器中“交叉”的意思就是在一个架构上编译另外一个架构的代码,相当于两种架构“交叉”起来了。
交叉编译器有很多种,我们使用 Linaro 出品的交叉编译器,Linaro 一间非营利性质的开放源代码软件工程公司,Linaro 开发了很多软件,最著名的就是 Linaro GCC 编译工具链(编译器),
一、下载GCC 编译器
Linaro GCC 编译器下载地址如下:
https://releases.linaro.org/components/toolchain/binaries/4.9-2017.01/arm-linux-gnueabihf/
图中有很多种交叉编译器,我们只需要关注这两种: gcc-linaro-4.9.4-2017.01-i686_arm-linux-gnueabihf.tar.tar.xz 和 gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz,第一个是针对 32 位系统的,第二个是针对 64 位系统的。如果安装的 Linux 是 64 位系统,则使用 gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz。
二、解压拷贝
解压交叉编译工具
sudo tar -vxf gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz
将交叉编译工具拷贝到一个特殊的路径,防止意外损坏。
mkdir /tool/arm
cp gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf /tool/arm/ -r
三、修改环境变量
修改环境变量,使用 VI 打开/etc/profile 文件,命令如下:
sudo vi /etc/profile
该方法是修改系统配置,需要管理员权限(如root)获取对该文件的写入权限:
# 如果/etc/profile文件不可编辑,需要修改为可编辑
chmod -v u+w /etc/profile
然后按 i,进入编辑模式,到文件末尾,添加环境参数
export PATH=$PATH:/tool/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin
添加完后,按esc,进入命令模式 。
执行:wq,保持此次修改
然后,就是执行soucre /etc/profile,使更改生效 。
四、检验是否安装成功
输入如下命令:
arm-linux-gnueabihf-gcc -v
如果交叉编译器安装正确的话就会显示版本号