Chinaunix首页 | 论坛 | 博客
  • 博客访问: 780209
  • 博文数量: 231
  • 博客积分: 3217
  • 博客等级: 中校
  • 技术积分: 2053
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-04 12:01
文章分类

全部博文(231)

文章存档

2015年(1)

2013年(10)

2012年(92)

2011年(128)

分类:

2012-06-02 11:59:32

crosstool-ng是新的用来建立交叉工具链的工具,它是crosstool的替换者.
使用crosstool最多只能编译gcc 4.1.1 glibc 2.x的版本.
而crosstool-ng一直保持着更新,现在最新能够建立 gcc 4.3.2版本 glibc 2.9版本...
在使用低于4.1.1的版本编译2.6.29 kernel时,会出现
include/linux/compiler-gcc4.h:7:3: error: #error Your version of gcc miscompiles the __weak directive
include/linux/compiler-gcc4.h:7 :如下
/* GCC 4.1.[01] miscompiles __weak */
#if __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ <= 1
# error Your version of gcc miscompiles the __weak directive
#endif
所以使用crosstool-ng建立一个新的工具链(gcc 4.3.2 glibc 2.9),以支持对最新kernel编绎.

测试环境:
Debian Linux 2.6.18-6-686
Ubuntu Linux 2.6.28-14     (Ubuntu 9.0.4)
1.crosstool-ng的安装
cd /tmp
mkdir crosstool-ng
wget
tar jxvf crosstool-ng-1.4.1.tar.bz2
cd /tmp/crosstool-ng-1.4.1
./configure --prefix=/opt/crosstool-ng
make
make install
echo "PATH=$PATH:/opt/crosstool-ng/bin" >> ~/.bashrc
source ~/.bashrc
ct-ng help
         ## ^ ^ 安装成功
2.安装必要工具包
#安装java开发包
sudo apt-get install gcj
#安装cvs
sudo apt-get install cvs
#切换mawk
sudo apt-get install gawk
cd /usr/bin
sudo mv mawk mawk.bak
sudo ln -s gawk mawk

Ubuntu 9.0.4 请先安装下 termcap 库   参考本文 错误与解决 4.. .
3.crosstool-ng使用范例
   本范例记录了使用crosstool-ng编绎arm-unknown-linux-gnueabi工具链的过程
cd /tmp/crosstool-ng
mkdir build_toolchain
cp /opt/crosstool-ng/lib/ct-ng-1.4.1/samples/arm-unknown-linux-gnueabi/crosstool.config .config
mkdir ~/src
vi .config
修改工具链安装路径
    CT_PREFIX_DIR="/opt/arm/4.3.2/${CT_TARGET}"
ct-ng build.4(用太多线程,很耗系统资源)
4.为工具链增加新链接
  
cd /opt/arm/4.3.2/arm-unknown-linux-gnueabi/bin
./autoln.sh
autoln.sh是一个脚本,用来自动链接arm-unknown-linux-gnueabi的工具...
文件名:autoln.sh 拷到要自动建立链接的文件夹使用。
#!/bin/bash

#
# main
#
if [ $# -lt 1 ] ; then
echo "default path: ./"
BIN_PATH=./
else
BIN_PATH=$1
fi
if [ ! -d $1 ] ; then
echo "path error"
exit
fi
cd $BIN_PATH
SRC=`ls | awk '{print $1}'`

for i in $SRC ; do
if [ "$i" != "autoln.sh" ] ; then
      #echo $i
      TARGET=`echo $i | sed 's/arm-unknown-linux-gnueabi/arm-linux/g' `
      echo $TARGET
      ln -s $i $TARGET
fi
done
  
错误与解决
1.[ERROR] Missing: 'i486-linux-gnu-gcj' or 'i486-linux-gnu-gcj' or 'gcj' : either needed!
   解决:sudo apt-get install gcj
2.
[ERROR]     Build failed in step 'Retrieving needed toolchain components' tarballs'
[ERROR]     Error happened in '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/functions' in function 'CT_DoExecLog' (line unknown, sorry)
[ERROR]           called from '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/functions' at line # 471 in function 'CT_GetCVS'
[ERROR]           called from '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/build/libc/glibc.sh' at line # 31 in function 'do_libc_get'
[ERROR]           called from '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/crosstool-NG.sh' at line # 449 in function 'main'
[ERROR]     Look at '/home/star/x-tools/arm-unknown-linux-gnueabi/build.log' for more info on this error.
[ERROR] (elapsed: 33:29.56)
[33:30] / make[1]: *** [build] 错误 127
make: *** [build.4] 错误 2
解决: sudo apt-get install cvs
3.
[INFO ] Installing C library headers
[EXTRA]     Configuring C library
[EXTRA]     Installing C library headers
[ERROR]     make[3]: *** [/home/star/x-tools/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi//sys-root/usr/include/gnu/lib-names.h] Error 1
[ERROR]     make[2]: *** [install-headers] Error 2
[ERROR]     Build failed in step 'Installing C library headers'
[ERROR]     Error happened in '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/functions' in function 'CT_DoExecLog' (line unknown, sorry)
[ERROR]           called from '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/build/libc/glibc.sh' at line # 185 in function 'do_libc_headers'
[ERROR]           called from '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/crosstool-NG.sh' at line # 494 in function 'main'
[ERROR]     Look at '/home/star/x-tools/arm-unknown-linux-gnueabi/build.log' for more info on this error.
[ERROR] (elapsed: 36:41.91)
[36:42] / make[1]: *** [build] 错误 2
make: *** [build.4] 错误 2
解决:查看build.log
[ALL ]     /usr/bin/install: cannot stat `/tmp/crosstool-ng/targets/arm-unknown-linux-gnueabi/build/build-libc-headers/gnu/li
b-names.h': No such file or directory
但在这之前也发生了一个error,但crosstool-ng并没有报错
[ALL ]     mawk: scripts/gen-sorted.awk: line 19: regular expression compile failed (bad class -- [], [^] or [)
[ALL ]     /[^
[ALL ]     mawk: scripts/gen-sorted.awk: line 19: syntax error at or near ]
[ALL ]     mawk: scripts/gen-sorted.awk: line 19: runaway regular expression /, "", subd ...
OK,在gen-sorted.awk第19行,出错,这是一个简单的错误,缺少了转义符
查找一个看有没有类似的  
  
   cd /tmp/crosstool-ng/targets/src/glibc-cvs-2.9/scripts 
 sed '/\^\//p' gen-sorted.awk -n
 输出的则是存在语法错误的语句
 可以直接用
 sed -i 's/\^\//\^\\\//g' gen-sorted.awk
   这种方法是不完善的,后面的还是会出现错误。
 网上搜了下,需要用/usr/bin/gawk 替换/usr/bin/mawk,即
   sudo apt-get install gawk
   cd /usr/bin
   sudo mv mawk mawk.bak
   sudo ln -s gawk mawk
3.
[INFO ] =================================================================
[INFO ] Installing C library
[EXTRA]     Configuring C library
[WARN ]     Removing "-pipe" for use with glibc>=2.6
[EXTRA]     Building C library
[ERROR]     make[4]: *** [/tmp/crosstool-ng/targets/arm-unknown-linux-gnueabi/build/build-libc/elf/ld.so] Error 2
[ERROR]     make[3]: *** [elf/subdir_lib] Error 2
[ERROR]     make[2]: *** [all] Error 2
[ERROR]     Build failed in step 'Installing C library'
[ERROR]     Error happened in '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/functions' in function 'CT_DoExecLog' (line unknown, sorry)
[ERROR]           called from '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/build/libc/glibc.sh' at line # 504 in function 'do_libc'
[ERROR]           called from '/opt/crosstool-ng/lib/ct-ng-1.4.1/scripts/crosstool-NG.sh' at line # 494 in function 'main'
[ERROR]     Look at '/home/star/x-tools/arm-unknown-linux-gnueabi/build.log' for more info on this error.
[ERROR] (elapsed: 32:05.76)
[32:06] / make[1]: *** [build] 错误 2
make: *** [build.4] 错误 2
解决:
   sudo apt-get install gawk
   cd /usr/bin
   sudo mv mawk mawk.bak
   sudo ln -s gawk mawk
4.
49567 [ERROR]    configure: error: no termcap library found
49568 [ERROR]    make[3]: *** [configure-gdb] Error 1
49569 [ALL ]    make[3]: Leaving directory `/opt/build_toolchain/targets/arm-unknown-linux-gnueabi/build/build-gdb-cross'
49570 [ERROR]    make[2]: *** [all] Error 2
49571 [ALL ]    make[2]: Leaving directory `/opt/build_toolchain/targets/arm-unknown-linux-gnueabi/build/build-gdb-cross'
49572 [ERROR]    Build failed in step 'Installing cross-gdb'
49573 [ERROR]    Error happened in '/usr/lib/ct-ng-1.4.1/scripts/functions' in function 'CT_DoExecLog' (line unknown, sorry)
49574 [ERROR]          called from '/usr/lib/ct-ng-1.4.1/scripts/build/debug/300-gdb.sh' at line # 126 in function 'do_debug      _gdb_build'
49575 [ERROR]          called from '/usr/lib/ct-ng-1.4.1/scripts/build/debug.sh' at line # 35 in function 'do_debug'
49576 [ERROR]          called from '/usr/lib/ct-ng-1.4.1/scripts/crosstool-NG.sh' at line # 494 in function 'main'
49577 [ERROR]    Look at '/opt/arm/4.3.2/arm-unknown-linux-gnueabi/build.log' for more info on this error.
49578 [ERROR] (elapsed: 72:30.97)

解决:
      这个问题我只在ubuntu 9.0.4中遇到过...缺少了termcap 库,但我在源里又没有搜到termcap相关的库(似乎是被其它库替换了,termcap这东西的确很古老)
      cd /tmp
      wget ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz
      tar zxvf
termcap-1.3.1.tar.gz
      cd termcap-1.3.1
      ./configure --prefix=/usr
      make
      make install
      (又需要从头编译工具链了 …… )

参考资料
1.crosstool-ng WIKI
阅读(1341) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~