CentOS7 安裝ARM Linux交叉編譯環境

1.Pre-built Toolchain傳送門html

總入口:https://www.linaro.org/downloads/python

Cortex-A系列處理器:https://releases.linaro.org/components/toolchain/binaries/linux

Cortex-R 和 Cortex-M系列處理器:https://launchpad.net/gcc-arm-embeddedc++

後面以GNU ARM Embedded Toolchain爲例app

2.安裝ide

因爲CentOS7安裝的是64位(查詢命令getconf LONG_BIT),所以須要安裝32位libc和libncurses函數

yum -y install glibc.i686ui

yum -y install ncursesspa

下載arm-none-eabi-gcc.net

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     }
View Code

編譯: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

看到上面的文字表示環境搭建大功告成了。

相關文章
相關標籤/搜索