使用crosstool_NG制作arm-linux交叉编译链

由于一般嵌入式开发系统的存储大小是有限的,通常要在PC机上编译然后下载到目标机上运行,这就需要交叉编译工具链。制作arm-linux交叉编译链一般可以使用crosstool_NG工具。

1. 下载crosstool_NG、GCC源码和构建工程

1.1 下载最新的crosstool_NG

1.2  下载GCC源码

1.3 建立项目文件

chy@chy-pc:~/arm-linux-obj$ ls
NG_build  NG_install  tool

1.4 解压文件

把crosstool_NG和GCC源码包解压到arm-linux-obj

2. 安装crosstool_NG

2.1 检查工程依赖

chy@chy-pc:~/arm-linux-obj/crosstool-ng$ ./configure --prefix ~/arm-linux-obj/NG_install/
通过 apt install xxx 来安装缺少的工具

2.2 编译安装

chy@chy-pc:~/arm-linux-obj/crosstool-ng$ make 
chy@chy-pc:~/arm-linux-obj/crosstool-ng$sudo  make  install

打印如下信息表示安装成功
For auto-completion, do not forget to install 'ct-ng.comp' into
your bash completion directory (usually /etc/bash_completion.d)

2.3 配环境变量

chy@chy-pc:~/arm-linux-obj/crosstool-ng$ sudo vim /etc/bash.bashrc 
在最后添加
export PATH=/home/chy/arm-linux-obj/NG_install/bin:$PATH
使刚配置的环境变量生效
chy@chy-pc:~/arm-linux-obj/crosstool-ng$ source /etc/bash.bashrc 

2.4 查看是否安装成功

chy@chy-pc:~/arm-linux-obj/crosstool-ng$ ct-ng -v
打印下面的信息说明安装成功
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

3. 配置交叉编译链

三星的s3c2440a处理器使用的是armv4t版本的指令集,arm920t的构架,没有硬浮点。通过man gcc 可以搜索arm,然后搜索-march=可以找到gcc支持的处理器核心表。(PS:在man中搜索,/要查找的关键字,即先键入/,在输入要查找的信息)。

3.1 选择配置文件

chy@chy-pc:~/arm-linux-obj/crosstool-ng$ ls ./samples/
alphaev56-unknown-linux-gnu           avr                                   powerpc64-unknown-linux-gnu
alphaev67-unknown-linux-gnu           i586-geode-linux-uclibc               powerpc-860-linux-gnu
arm-bare_newlib_cortex_m3_nommu-eabi  i586-mingw32msvc,i686-none-linux-gnu  powerpc-e300c3-linux-gnu
arm-cortex_a15-linux-gnueabi          i686-nptl-linux-gnu                   powerpc-e500v2-linux-gnuspe
arm-cortexa5-linux-uclibcgnueabihf    i686-w64-mingw32                      powerpc-unknown-linux-gnu
arm-cortex_a8-linux-gnueabi           i686-w64-mingw32,nios2-spico-elf      powerpc-unknown-linux-uclibc
arm-cortexa9_neon-linux-gnueabihf     m68k-unknown-elf                      powerpc-unknown_nofpu-linux-gnu
armeb-unknown-eabi                    m68k-unknown-uclinux-uclibc           s390-ibm-linux-gnu
armeb-unknown-linux-gnueabi           mips64el-n32-linux-uclibc             s390x-ibm-linux-gnu
armeb-unknown-linux-uclibcgnueabi     mips64el-n64-linux-uclibc             samples.mk
arm-unknown-eabi                      mips-ar2315-linux-gnu                 sh4-unknown-linux-gnu
arm-unknown-linux-gnueabi             mipsel-sde-elf                        sparc-unknown-linux-gnu
arm-unknown-linux-musleabi            mipsel-unknown-linux-gnu              x86_64-unknown-linux-gnu
arm-unknown-linux-uclibcgnueabi       mips-malta-linux-gnu                  x86_64-unknown-linux-uclibc
arm-unknown-linux-uclibcgnueabihf     mips-unknown-elf                      x86_64-w64-mingw32
armv6-rpi-linux-gnueabi               mips-unknown-linux-uclibc             x86_64-w64-mingw32,x86_64-pc-linux-gnu
armv7-rpi2-linux-gnueabihf            powerpc-405-linux-gnu                 xtensa-unknown-linux-uclibc
选择arm、linux的配置文件:arm-unknown-linux-gnueabi 

3.2 进入配置页面

拷贝配置文件到NG_build并改名为.config
chy@chy-pc:~/arm-linux-obj/crosstool-ng$ cp ./samples/arm-unknown-linux-gnueabi/crosstool.config ~/arm-linux-obj/NG_build/.config

进入配置页面
chy@chy-pc:~/arm-linux-obj/NG_build$ ct-ng menuconfig

3.3 配置源码路径和交叉编译器的安装路径


图一


图二
以上信息根据自己的实际路径设置。

3.4 修改交叉编译器的构架(Target options)


图三
以上信息根据自己的实际路径设置。

3.5 修改编译器默认名称
chy@chy-pc:~/arm-linux-obj/NG_build$ vim ./.config
找到
CT_TARGET_VENDOR="unknow" 修改为自己想要的名称

3.6 更改linux内核版


图四


图五

3.7 开始编译

chy@chy-pc:~/arm-linux-obj/NG_build$ ct-ng build
大概需要一个多小时

3.8 查看是否编译成功

chy@chy-pc:~/arm-linux-obj/tool/bin$ ./arm-ChenHongyu-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=./arm-ChenHongyu-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/home/chy/arm-linux-obj/tool/libexec/gcc/arm-ChenHongyu-linux-gnueabi/5.2.0/lto-wrapper
Target: arm-ChenHongyu-linux-gnueabi
Configured with: /home/chy/arm-linux-obj/NG_build/.build/src/gcc-5.2.0/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-ChenHongyu-linux-gnueabi --prefix=/home/chy/arm-linux-obj/tool --with-sysroot=/home/chy/arm-linux-obj/tool/arm-ChenHongyu-linux-gnueabi/sysroot --enable-languages=c,c++ --with-cpu=arm920t --with-float=soft --with-pkgversion='crosstool-NG crosstool-ng-1.22.0' --disable-sjlj-exceptions --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --with-gmp=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-mpfr=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-mpc=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-isl=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-cloog=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-libelf=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/chy/arm-linux-obj/tool/arm-ChenHongyu-linux-gnueabi/sysroot --enable-long-long
Thread model: posix
gcc version 5.2.0 (crosstool-NG crosstool-ng-1.22.0) 

4. 安装crosstool_NG过程中遇到的问题

(1)出现:configure: error: missing required tool: gperf
安装gperf: sudo apt install gperf

(2)出现:configure: error: missing required tool: bison
安装bison:sudo apt install bison

(3)出现:configure: error: missing required tool: flex
安装flex:sudo apt install flex

(4)出现:configure: error: missing required tool: makeinfo
安装 makeinfo:sudo apt install makeinfo
如果提示:E: 无法定位软件包 makeinfo
则先安装:texinfo

(5)出现:configure: error: missing required tool: help2man
安装help2man:sudo apt install help2man

(6)出现:configure: error: could not find GNU awk
安装gawk:sudo apt install gawk

(7)出现:configure: error: could not find GNU libtool >= 1.5.26
安装libtool-bin:sudo apt install libtool-bin

(8)出现:configure: error: could not find GNU automake >= 1.10
安装automake:sudo apt install automake

(9)出现:configure: error: could not find curses header, required for the kconfig frontends
安装libncurses5-dev:sudo apt-get install libncurses5-dev

5. 安装交叉编译器

5.1 把arm-linux复制到/opt目录下

chy@chy-pc:~$ sudo cp -r ./arm-linux-obj/tool/ /opt/

5.2 配置环境变量

打开配置文件:
chy@chy-pc:~$ sudo vim /etc/bash.bashrc 
在最后添加:
export PATH=/opt/tool/bin:$PATH
使环境变量生效:
chy@chy-pc:~$ source /etc/bash.bashrc

5.3 验证是否安装成功

chy@chy-pc:~$ arm-ChenHongyu-linux-gnueabi-gcc -v
出现下面的信息则安装成功
Using built-in specs.
COLLECT_GCC=arm-ChenHongyu-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/opt/tool/bin/../libexec/gcc/arm-ChenHongyu-linux-gnueabi/5.2.0/lto-wrapper
Target: arm-ChenHongyu-linux-gnueabi
Configured with: /home/chy/arm-linux-obj/NG_build/.build/src/gcc-5.2.0/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-ChenHongyu-linux-gnueabi --prefix=/home/chy/arm-linux-obj/tool --with-sysroot=/home/chy/arm-linux-obj/tool/arm-ChenHongyu-linux-gnueabi/sysroot --enable-languages=c,c++ --with-cpu=arm920t --with-float=soft --with-pkgversion='crosstool-NG crosstool-ng-1.22.0' --disable-sjlj-exceptions --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --with-gmp=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-mpfr=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-mpc=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-isl=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-cloog=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --with-libelf=/home/chy/arm-linux-obj/NG_build/.build/arm-ChenHongyu-linux-gnueabi/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/chy/arm-linux-obj/tool/arm-ChenHongyu-linux-gnueabi/sysroot --enable-long-long
Thread model: posix
gcc version 5.2.0 (crosstool-NG crosstool-ng-1.22.0) 



  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Using built-in specs. COLLECT_GCC=./arm-cortexa9_neon-linux-uclibcgnueabihf-gcc COLLECT_LTO_WRAPPER=/opt/toolchains/arm-cortexa9_neon-linux-uclibcgnueabihf-gcc-7.4.0/bin/../libexec/gcc/arm-cortexa9_neon-linux-uclibcgnueabihf/7.4.0/lto-wrapper Target: arm-cortexa9_neon-linux-uclibcgnueabihf Configured with: /home/abu/arm/u-boot-2019.04/.build/arm-cortexa9_neon-linux-uclibcgnueabihf/src/gcc/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-cortexa9_neon-linux-uclibcgnueabihf --prefix=/home/abu/x-tools/arm-cortexa9_neon-linux-uclibcgnueabihf --with-sysroot=/home/abu/x-tools/arm-cortexa9_neon-linux-uclibcgnueabihf/arm-cortexa9_neon-linux-uclibcgnueabihf/sysroot --enable-languages=c,c++,fortran --with-cpu=cortex-a9 --with-fpu=neon --with-float=hard --with-pkgversion='crosstool-NG 1.24.0' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=/home/abu/arm/u-boot-2019.04/.build/arm-cortexa9_neon-linux-uclibcgnueabihf/buildtools --with-mpfr=/home/abu/arm/u-boot-2019.04/.build/arm-cortexa9_neon-linux-uclibcgnueabihf/buildtools --with-mpc=/home/abu/arm/u-boot-2019.04/.build/arm-cortexa9_neon-linux-uclibcgnueabihf/buildtools --with-isl=/home/abu/arm/u-boot-2019.04/.build/arm-cortexa9_neon-linux-uclibcgnueabihf/buildtools --disable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++ -lm' --enable-threads=posix --enable-target-optspace --disable-plugin --with-libintl-prefix=/home/abu/arm/u-boot-2019.04/.build/arm-cortexa9_neon-linux-uclibcgnueabihf/buildtools --disable-multilib --with-local-prefix=/home/abu/x-tools/arm-cortexa9_neon-linux-uclibcgnueabihf/arm-cortexa9_neon-linux-uclibcgnueabihf/sysroot --enable-long-long Thread model: posix gcc version 7.4.0 (crosstool-NG 1.24.0)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值