linux交叉編譯的安裝

聲明:本文來與http://biancheng.dnbcw.info/linux/269048.htmlhtml

前段時間用了幾個編譯器,版本太多,感受用起來不是很爽。參考了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 /optjava

3)安裝

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

出現以下提示信息

[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]#
linux

從上面能夠看到,./configure時首先檢查了一些必須的軟件,另外提示「automake 1.10 or above was not found」,即本機上automake版本過低,須要 1.10版本或以上。sql

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

而後解壓安裝automakebash

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

提示信息以下less

[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]#
ide

從提示的信息能夠看出,本機上的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,修改配置

下面對默認的配置做簡單的修改

一、已下載好的源碼包路徑和交叉編譯器的安裝路徑。
Paths and misc options  --->
  (/opt/src) Local tarballs directory   保存源碼包路徑
  (${HOME}/x-tools/${CT_TARGET}) Prefix directory  交叉編譯器的安裝路徑

二、修改交叉編譯器針對的構架。
Target options  --->
  *** Target optimisations ***
           (armv4t) Architecture level
           (arm9tdmi) Emit assembly for CPU   
           (arm920t) Tune for CPU

三、關閉java編譯器,避免gcj出錯
C compiler  --->
      *** Additional supported languages: ***
      [N] Java 

四、一些個性化的設置
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之製做交叉編譯器來源網絡,若有侵權請告知,即處理!

相關文章
相關標籤/搜索