linux交叉编译的安装

声明:本文来与http://biancheng.dnbcw.info/linux/269048.html

前段时间用了几个编译器,版本太多,感觉用起来不是很爽。参考了Tekkaman Ninja大侠的文章,决定自己动手制作交叉编译器。

参考资料
1)《用crosstool-ng建立linux交叉编译环境》
    原文地址:http://blog.chinaunix.net/u1/34474/showart_2198589.html
    Tekkaman Ninja大侠的这篇文章,详尽地记录了制作交叉编译工具的整个过程,浅显易懂,很具有参考价值
2) crosstool-ng-1.7.1中的overview.txt文档
    为了了解一款软件,我们常常会去读它的相关文档。crosstool-ng-1.7.1中docs目录下的overview.txt文档,对整个软件的安装都作了详细的描述,推荐去阅读一下
3) crosstool-ng-1.7.1中的Makefile.in文档
    看了Tekkaman Ninja大侠的文章,可能有人要问,到底要安装哪些软件包?仔细看看Makefile.in文件吧,它会给你答案的

言归正传,下面介绍本人在RHEL5.1上制作交叉编译器的全过程
一.下载并安装crosstool-ng
1)下载crosstool-ng-1.7.1.tar.bz2
     软件包下载地址http://ymorin.is-a-geek.org/download/crosstool-ng/crosstool-ng-1.7.1.tar.bz2
2)解压

tar -jxvf crosstool-ng-1.7.1.tar.bz2 -C /opt

3)安装

cd /opt/crosstool-ng-1.7.1
./configure

出现如下提示信息

[root@localhost crosstool-ng-1.7.1]# ./configure
Checking for 'grep'... /bin/grep
Checking whether '/bin/grep' supports -E... yes
Checking for 'sed'... /bin/sed
Checking whether '/bin/sed' supports -i and -e... yes
Checking for 'bash'... /bin/bash
Checking for 'cut'... /bin/cut
Checking for 'install'... /usr/bin/install
Checking for 'make'... /usr/bin/make
Checking for 'gcc'... /usr/bin/gcc
Checking for 'awk'... /bin/awk
Checking for 'bison'... /usr/bin/bison
Checking for 'flex'... /usr/bin/flex
Checking for 'makeinfo'... /usr/bin/makeinfo
Checking for 'automake'... no
automake 1.10 or above was not found
Either you are missing entirely the needed tool,
or the version you have is too old.
configure: Bailing out...
[root@localhost crosstool-ng-1.7.1]#

从上面可以看到,./configure时首先检查了一些必须的软件,另外提示“automake 1.10 or above was not found”,即本机上automake版本太低,需要 1.10版本或以上。

下载automake-1.10.2.tar.bz2, 下载地址http://mirrors.ispros.com.bd/gnu/automake/automake-1.10.2.tar.bz2

然后解压安装automake

tar -jxvf automake-1.10.2.tar.bz2 -C /opt
cd /opt/automake-1.10.2/
./configure

提示信息如下

[root@localhost automake-1.10.2]# ./configure
checking build system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for perl... /usr/bin/perl
checking for tex... no
checking whether autoconf is installed... yes
checking whether autoconf works... yes
checking whether autoconf is recent enough... no
configure: error: Autoconf 2.60 or better is required.
[root@localhost automake-1.10.2]#

从提示的信息可以看出,本机上的autoconf版本太低。

下载autoconf-2.66.tar.bz2,下载地址为http://mirrors.ispros.com.bd/gnu/autoconf/autoconf-2.66.tar.bz2

然后解压安装autoconf

tar -jxvf autoconf-2.66.tar.bz2 -C /opt
cd /opt/autoconf-2.66/
./configure
make
make install


autoconf安装成功之后,再来安装automake

cd /opt/automake-1.10.2/
./configure
make
make install

automake和autoconf都安装好了,现在来安装crosstool-ng。

cd /opt/crosstool-ng-1.7.1/
./configure


提示信息如下

lzma: none found
Either you are missing entirely the needed tool,
or the version you have is too old.
configure: Bailing out...
[root@localhost crosstool-ng-1.7.1]#


从提示信息可以看出,本机上缺少lzma.

下载lzma-4.32.7.tar.bz2, 下载地址为http://tukaani.org/lzma/lzma-4.32.7.tar.bz2

解压并安装lzma

tar -jxvf lzma-4.32.7.tar.bz2 -C /opt
cd /opt/lzma-4.32.7
./configure
make
make install


okay,现在就可以成功安装crosstool-ng了。

cd /opt/crosstool-ng-1.7.1/
./configure
make
make install


运行ct-ng --help

[root@localhost crosstool-ng-1.7.1]# ct-ng --help
用法:make [选项] [目标] ...
选项:
  -b, -m Ignored for compatibility.
  -B, --always-make Unconditionally make all targets.
  -C DIRECTORY, --directory=DIRECTORY
                              Change to DIRECTORY before doing anything.
  -d Print lots of debugging information.
  --debug[=FLAGS] Print various types of debugging information.
  -e, --environment-overrides
                              Environment variables override makefiles.
  -f FILE, --file=FILE, --makefile=FILE
                              Read FILE as a makefile.
  -h, --help Print this message and exit.
  -i, --ignore-errors Ignore errors from commands.
  -I DIRECTORY, --include-dir=DIRECTORY
                              Search DIRECTORY for included makefiles.
  -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.
  -k, --keep-going Keep going when some targets can't be made.
  -l [N], --load-average[=N], --max-load[=N]
                              Don't start multiple jobs unless load is below N.
  -L, --check-symlink-times Use the latest mtime between symlinks and target.
  -n, --just-print, --dry-run, --recon
                              Don't actually run any commands; just print them.
  -o FILE, --old-file=FILE, --assume-old=FILE
                              Consider FILE to be very old and don't remake it.
  -p, --print-data-base Print make's internal database.
  -q, --question Run no commands; exit status says if up to date.
  -r, --no-builtin-rules Disable the built-in implicit rules.
  -R, --no-builtin-variables Disable the built-in variable settings.
  -s, --silent, --quiet Don't echo commands.
  -S, --no-keep-going, --stop
                              Turns off -k.
  -t, --touch Touch targets instead of remaking them.
  -v, --version Print the version number of make and exit.
  -w, --print-directory Print the current directory.
  --no-print-directory Turn off -w, even if it was turned on implicitly.
  -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE
                              Consider FILE to be infinitely new.
  --warn-undefined-variables Warn when an undefined variable is referenced.
This program built for i686-redhat-linux-gnu
Report bugs to <bug-make@gnu.org>
[root@localhost crosstool-ng-1.7.1]#

到这里,万里长征总算走完了第一步。
二. 配置编译的交叉编译工具
接下来就是配置要编译的交叉编译工具了。crosstool-ng有很多已经做好的默认配置,位于crosstool-ng-X.Y.Z/samples目录下,你只要针对其进行修改就好了。

mkdir /opt/ct-ng-build          #建立工作目录
cp /opt/crosstool-ng-1.7.1/samples/arm-unknown-linux-gnueabi/* /opt/ct-ng-build      #拷贝默认配置
cd /opt/ct-ng-build             #进入工作目录
mv crosstool.config ./config    #修改文件名
ct-ng menuconfig                #进入menuconfig,修改配置

下面对默认的配置作简单的修改

1、已下载好的源码包路径和交叉编译器的安装路径。
Paths and misc options  --->
  (/opt/src) Local tarballs directory   保存源码包路径
  (${HOME}/x-tools/${CT_TARGET}) Prefix directory  交叉编译器的安装路径

2、修改交叉编译器针对的构架。
Target options  --->
  *** Target optimisations ***
           (armv4t) Architecture level
           (arm9tdmi) Emit assembly for CPU   
           (arm920t) Tune for CPU

3、关闭java编译器,避免gcj出错
C compiler  --->
      *** Additional supported languages: ***
      [N] Java 

4、一些个性化的设置
Toolchain options  --->
       *** Tuple completion and aliasing *** 
       (grubbyhunter) Tuple's vendor string
这样产生的编译器前缀就是:arm-grubbyhunter-linux-gnueabi-

 
 
当然有时候会感觉这个前缀太长,crosstool-ng也很人性化,可以在配置的时候设置别名。
Toolchain options  --->
       *** Tuple completion and aliasing *** 
       (arm-linux) Tuple's alias  
 这里设置为arm-linux这样,以后通过arm-linux-gcc就可以调用arm-grubbyhunter-linux-gnueabi-gcc了。(还是arm-linux-gcc看着舒服啊,嘿嘿!)
接下来保存就可以了
三. 下载相关的软件包
在编译的过程中,ct-ng会去下载一些软件包(如果没有的话),这里提前下载一些软件包,可以减少编译的时间。那么到底需要哪些软件包呢?

vi /opt/ct-ng-build/.config

无图无真相,现在就来看一下,.config文件中可以找到如下这些东东

CT_KERNEL_VERSION="2.6.33.2"      #linux-2.6.33.2.tar.bz2

CT_BINUTILS_VERSION="2.19.1"      #binutils-2.19.1.tar.bz2    
CT_SSTRIP=y                       #sstrip.c
CT_CC_VERSION="4.3.2"             #gcc-4.3.2.tar.bz2

CT_LIBC_VERSION="2.9"             #glibc-2.9.tar.gz

CT_LIBC_GLIBC_USE_PORTS=y         #glibc-ports-2.9.tar.bz2 
CT_DMALLOC_VERSION="5.5.2"        #dmalloc-5.5.2.tgz

CT_DUMA_VERSION="2_5_15"          #duma-2.5.15.tar.gz
CT_GDB_VERSION="6.8"              #gdb-6.8.tar.bz2
CT_LTRACE_VERSION="0.5.3"         #ltrace-0.5.3.tar.gz
CT_STRACE_VERSION="4.5.19"        #strace-4.5.19.tar.bz2
CT_GMP_VERSION="4.3.2"            #gmp-4.3.2.tar.bz2
CT_MPFR_VERSION="2.4.2"           #mpfr-2.4.2.tar.bz2
CT_LIBELF_VERSION="0.8.13"        #libelf-0.8.13.tar.gz

下载完之后,记得将这些软件包放在配置时指定的文件夹,本机是/opt/src。
见http://blog.sina.com.cn/s/blog_a5db27840101d7cf.html

四. 编译

cd /opt/ct-ng-build
ct-ng build

然后,一堆貌似很NB的文字在面前飘过,这时候去喝杯咖啡,散散心啥的,大约1小时之后编译完成。

五. 测试

关于编译内核和根文件系统的测试,将在后面章节陆续给出。

“嵌入式linux之制作交叉编译器”的更多相关文章 》

相关资料:

嵌入式linux之制作交叉编译器来源网络,如有侵权请告知,即处理!

posted on 2015-04-27 15:36  LeoSanford  阅读(715)  评论(0编辑  收藏  举报

levels of contents