安装制作交叉编译器的工具:crosstool-ng(含解决configure: error: could not find bash >= 3.1的全网最详细方法)

一、安装crosstool-ng的步骤

1.下载(不建议下最新版,因为一旦出现了问题,在全网搜寻不到好的解决办法…)

我尝试了最新版crosstool-ng-1.23.0后的辛酸建议,建议下载crosstool-1.18.0(已经成功安装)
在这里插入图片描述
.bz2: linux下常见的压缩文件格式,7-zip工具可解压得到crosstool-ng-1.18.0.tar,将其拷贝到VMware的ubuntu20.04LTS中(VMware Tools, 我的VMware版本号16.0.0)。我选择的目录:~/CS/experimentBCSD/crosstool-ng

2.解压

tar xvf crosstool-ng-1.18.0.tar
在这里插入图片描述

3.配置(见“二、配置crosstool-ng-1.18.0”)

4.编译(见“三、编译crosstool-ng-1.18.0”)

5.安装(见“四、安装crosstool-ng-1.18.0”)

6.测试(见“五、测试crosstool-ng-1.18.0”)

二、配置crosstool-ng-1.18.0

1. 命令

./configure --prefix=/home/forrest/CS/crosstool-ng

–prefix = 安装路径
在这里插入图片描述

2.遇到的一堆问题

(1)configure: error: missing required tool: gperf
解决办法sudo apt-get install gperf

(2)configure: error: missing required tool: bison
解决办法sudo apt-get install bison

(3)configure: error: missing required tool: flex
解决办法sudo apt-get install flex

(4)configure: error: missing required tool: makeinfo
解决办法sudo apt-get install texinfo

(5)configure: error: missing required tool: help2man
解决办法:sudo apt-get install -y help2man

-y : 在需要确认的场景中回应yes

(6)configure: error: could not find bash >= 3.1
①修改configure.ac
安装制作交叉编译器的工具:crosstool-ng(含解决configure: error: could not find bash >= 3.1的全网最详细方法)_第1张图片

关键:$EGREP '^GNU bash(, version)|(,版本) ([3-9]\.\d+\.\d+)')要去匹配GNU bash,版本 5.0.17(因为我的bash版本是5.0.17)

安装制作交叉编译器的工具:crosstool-ng(含解决configure: error: could not find bash >= 3.1的全网最详细方法)_第2张图片

之后要重新生成configure,参考方法:linux使用—automake学习(从原理到实践,一步步完成automake)

②重新生成configure的准备工作

  • sudo apt-get install automake
  • sudo apt-get install autoconf (可能已经装好了)

③根据下图,得到aclocal.m4、config.h.in和新的configure
安装制作交叉编译器的工具:crosstool-ng(含解决configure: error: could not find bash >= 3.1的全网最详细方法)_第3张图片

  • aclocal: 得到aclocal.m4
    在这里插入图片描述
  • autoconf: 得到新的configure;autoheader: 得到config.h.in
    在这里插入图片描述
  • 得到如下3个文件后,./configure --prefix=/home/forrest/CS/crosstool-ng即可
    在这里插入图片描述

(7)configure: error: could not find GNU awk
解决办法sudo apt-get install gawk

(8)configure: error: could not find GNU libtool >= 1.5.26
解决办法./configure --prefix=/home/forrest/CS/crosstool-ng --with-libtool=/usr/share/libtool

参考方法:crosstool error: could not find GNU libtool >= 1.5.26

至此,恭喜小伙伴们千辛万苦完成了配置!!!

三、编译crosstool-ng-1.18.0

1.命令:make

2.遇到了一些问题

(1)Recursion detected, bailing out
在这里插入图片描述

  • 解决办法:
    在这里插入图片描述
    安装制作交叉编译器的工具:crosstool-ng(含解决configure: error: could not find bash >= 3.1的全网最详细方法)_第4张图片

参考方法:Solution: infinite recursion during the make step in older CT-NG versions
在这里插入图片描述
重新配置,再make

(2)error: conflicting types for ‘kconf_id_lookup’
在这里插入图片描述

  • 解决办法:将size_t换成了unsigned int
    安装制作交叉编译器的工具:crosstool-ng(含解决configure: error: could not find bash >= 3.1的全网最详细方法)_第5张图片

再一次先./configure --prefix=/home/forrest/CS/crosstool-ng --with-libtool=/usr/share/libtoolmake
至此,恭喜小伙伴们成功完成编译!!!

四、安装crosstool-ng-1.18.0

1.命令:make install

安装制作交叉编译器的工具:crosstool-ng(含解决configure: error: could not find bash >= 3.1的全网最详细方法)_第6张图片

难得这么顺利!!!

五、测试crosstool-ng-1.18.0

1.添加环境变量
echo "PATH=$PATH:/home/forrest/CS/crosstool-ng/bin" >> ~/.zshrc
source ~/.zshrc

注意:我装了zsh,有的小伙伴们可能还是bash,所以是~/.bashrc

2.测试:ct-ng help
在这里插入图片描述

六、尾声

1. 最主要的参考文档:【记录】在Cygwin下编译gcc-3.4.5-glibc-2.3.6的arm-xscale-linux-gnu交叉编译器

2. 感谢大佬crifan大神的耐心帮助

3. 写作不易,希望辛勤付出能够为小伙伴们排忧解难,如果觉得有帮助,点赞、评论、收藏或关注就是最大的支持了,谢谢哈。

你可能感兴趣的:(搭建环境,交叉编译,crosstool-ng,交叉编译)