CentOS7 安装ARM Linux交叉编译环境
2017-01-20 22:56 miscellaneous 阅读(13979) 评论(0) 编辑 收藏 举报1.Pre-built Toolchain传送门
总入口:https://www.linaro.org/downloads/
Cortex-A系列处理器:https://releases.linaro.org/components/toolchain/binaries/
Cortex-R 和 Cortex-M系列处理器:https://launchpad.net/gcc-arm-embedded
后面以GNU ARM Embedded Toolchain为例
2.安装
由于CentOS7安装的是64位(查询命令getconf LONG_BIT),因此需要安装32位libc和libncurses
yum -y install glibc.i686
yum -y install ncurses
下载arm-none-eabi-gcc
wget https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
解压
tar -xjf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
拷贝到/usr/local目录(可选)
mv gcc-arm-none-eabi-5_4-2016q3 /usr/local/gcc-arm-none-eabi
修改环境变量
vi /etc/profile 插入export PATH=$PATH:/usr/local/gcc-arm-none-eabi/bin
运行source /etc/profile使环境变量生效
3.检查
运行arm-none-eabi-gcc -v, 看到如下提示:
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/lto-wrapper
Target: arm-none-eabi
Configured with: /home/build/work/GCC-5-build/src/gcc/configure --target=arm-none-eabi --prefix=/home/build/work/GCC-5-build/install-native --libexecdir=/home/build/work/GCC-5-build/install-native/lib --infodir=/home/build/work/GCC-5-build/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/home/build/work/GCC-5-build/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/home/build/work/GCC-5-build/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/home/build/work/GCC-5-build/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/home/build/work/GCC-5-build/install-native/arm-none-eabi --build=i686-linux-gnu --host=i686-linux-gnu --with-gmp=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-mpfr=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-mpc=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-isl=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-cloog=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-libelf=/home/build/work/GCC-5-build/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for ARM Embedded Processors' --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r,armv8-m.base,armv8-m.main
Thread model: single
gcc version 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496] (GNU Tools for ARM Embedded Processors)
写个hello world验证一把
1 #include <stdio.h> 2 int main() 3 { 4 printf("Hello World!\n"); 5 return 0; 6 }
编译:arm-none-eabi-gcc --specs=nosys.specs -o main main.c
(如果编译有错误,可能是默认的libc缺少某些标准函数,需要使用--specs选项。arm-none-eabi-gcc配套的readme文件中有关于libc库及--specs选项的解释,如https://launchpadlibrarian.net/287100883/readme.txt。使用前建议阅读一下readme文件)
查看文件信息:file main
main: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
看到上面的文字表示环境搭建大功告成了。