Preface
前面编译linux内核的时候,用各种cross版本都不行啊,真是纠结,于是就想着自己也要会编译交叉工具的方法,然后各种尝试,各种问题啊,最后还是没解决(还有其它事情),步骤我都走熟了,记下来吧
Preparation
root@lcw:/home/mystery/cross_toolchain# ls binutils-2.15.tar.bz2 glibc-2.3.2.tar.bz2 crosstool-0.43 glibc-linuxthreads-2.3.2.tar.bz2 crosstool-0.43.tar.gz linux-2.6.14.tar.bz2 gcc-4.1.0.tar.bz2 linux-libc-headers-2.6.12.0.tar.bz2
后面还下载了gdb-6.5.tar.bz2
#!/bin/sh set -ex TARBALLS_DIR=/home/mystery/cross_toolchain/crossTools # 定义工具链源码所存放位置。 RESULT_TOP=/opt/crosstool # 定义工具链的安装目录 export TARBALLS_DIR RESULT_TOP GCC_LANGUAGES="c,c++" # 定义支持C, C++语言 export GCC_LANGUAGES # 创建/opt/crosstool目录 mkdir -p $RESULT_TOP # 编译工具链,该过程需要数小时完成。 eval 'cat arm.dat gcc-4.1.0-glibc-2.3.2.dat' sh all.sh --notest echo Done.
Step3
<gcc-4.1.0-glibc-2.3.2.dat> BINUTILS_DIR=binutils-2.15 GCC_DIR=gcc-3.3.6 GLIBC_DIR=glibc-2.3.2 GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.2 LINUX_DIR=linux-2.6.14 LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.12.0
<arm.dat>
KERNELCONFIG='pwd'/arm.config # 内核的配置 TARGET=arm-linux- # 编译生成的工具链名称 TARGET_CFLAGS="-O" # 编译选项
Step4
执行脚本,将Crosstool的脚本文件和配置文件准备好之后,开始执行arm.sh脚本来编译交叉编译工具。如果顺利的话,这步经过数个小时后,就能生成交叉编译工具了,数个小时啊,准备迎接各种error吧
<Question1>
+ abort Don't run all.sh or crosstool.sh as root, it's dangerous + echo Don't run all.sh or crosstool.sh as root, it's dangerous Don't run all.sh or crosstool.sh as root, it's dangerous
<Solution>:这脚本够纠结的,用普通帐户时,执行命令又权限不够,用root帐户,又不让你运行,那么
<Question2>
patching file linuxthreads/sysdeps/unix/sysv/linux/arm/sysdep-cancel.h grep: /home/mystery/cross_toolchain/crosstool-0.43/build/arm-linux/gcc-4.1.0-glibc-2.3.2/binutils-2.16.1/patches/README: No such file or directory + test = + [ -d /opt/crosstool/gcc-4.1.0-glibc-2.3.2/arm-linux ] + mkdir -p /opt/crosstool/gcc-4.1.0-glibc-2.3.2/arm-linux mkdir: cannot create directory `/opt/crosstool/gcc-4.1.0-glibc-2.3.2': Permission denied
mystery@lcw:/opt$ ls -l total 36 drwxr-xr-x 2 root root 4096 Apr 7 20:26 crosstool drwxrwsr-x 9 messagebus users 4096 Feb 25 12:39 eclipse drwxr-xr-x 3 root root 4096 Apr 4 10:47 google drwxr-xr-x 8 500 500 4096 Mar 1 19:36 jdk1.7.0_17 drwxr-xr-x 3 root root 4096 Apr 4 11:25 kingsoft drwx------ 2 root root 16384 Apr 4 09:32 lost+found mystery@lcw:/opt$ chgrp mystery crosstool/ chgrp: changing group of `crosstool/': Operation not permitted mystery@lcw:/opt$ sudo chgrp mystery crosstool/ [sudo] password for mystery: mystery@lcw:/opt$ sudo chown mystery crosstool/ mystery@lcw:/opt$ ls -l total 36 drwxr-xr-x 2 mystery mystery 4096 Apr 7 20:26 crosstool drwxrwsr-x 9 messagebus users 4096 Feb 25 12:39 eclipse drwxr-xr-x 3 root root 4096 Apr 4 10:47 google drwxr-xr-x 8 500 500 4096 Mar 1 19:36 jdk1.7.0_17 drwxr-xr-x 3 root root 4096 Apr 4 11:25 kingsoft drwx------ 2 root root 16384 Apr 4 09:32 lost+found
<Question3>
/home/mystery/cross_toolchain/crosstool-0.43/crosstool.sh: 110: /home/mystery/cross_toolchain/crosstool-0.43/crosstool.sh: bison: not found crosstool: You don't have bison installed
Solution:这种是最简单的,缺什么装什么,不过最好把这个记一下,不然以后装多了,你都不知道自己电脑上装了些什么
mystery@lcw:~/cross_toolchain/crosstool-0.43$ sudo apt-get install bison
<Question4>
oss_toolchain/crosstool-0.43/crosstool.sh: flex: not found crosstool: You don't have flex installed
solution:同上
mystery@lcw:~/cross_toolchain/crosstool-0.43$ sudo apt-get install flex
<Question5>
checking for pwd... /bin/pwd checking for arm-linux-gcc... gcc checking version of gcc... 4.6.3, bad checking for gnumake... no checking for gmake... no checking for make... make checking version of make... 3.81, ok configure: error: *** These critical programs are missing or too old: gcc *** Check the INSTALL file for required versions
意思是说,我系统的GCC版本太高了(4.6.3,目录最高版本,也是系统默认版本),版本太高了也不好啊,由于crosstools最后只支持gcc-4.1.0版本的,那我去下个GCC-4.1.0的吧。换了几个源,都没有找到4.1的,只好去网上找了
mystery@lcw:~/Downloads$ dpkg -l "*gcc*" Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Description +++-==============-==============-============================================ ii gcc 4:4.6.3-1ubunt GNU C compiler un gcc-4.1 <none> (no description available) ri gcc-4.1-base 4.1.2-27ubuntu The GNU Compiler Collection (base package) un gcc-4.1-doc <none> (no description available) un gcc-4.1-locale <none> (no description available) un gcc-4.1-multil <none> (no description available) un gcc-4.3 <none> (no description available) un gcc-4.4 <none> (no description available) un gcc-4.4-base <none> (no description available) un gcc-4.5 <none> (no description available) un gcc-4.5-base <none> (no description available) ii gcc-4.6 4.6.3-1ubuntu5 GNU C compiler ri gcc-4.6-base 4.6.3-1ubuntu5 GCC, the GNU Compiler Collection (base packa un gcc-4.6-doc <none> (no description available) un gcc-4.6-locale <none> (no description available) un gcc-4.6-multil <none> (no description available) un gcc-doc <none> (no description available) un gcc-multilib <none> (no description available) ri libgcc1 1:4.6.3-1ubunt GCC support library un libgcc1-dbg <none> (no description available)
最多装上了gcc-4.1,及base,后面因为依赖关系涉及到lib和libgcc,看网上说的,如果直接完全卸载
Step5
解压gcc-4.1.0的源码,然后执行
mystery@lcw:~/Downloads$ # ./configure --prefix=/opt/gcc-4.1&& make
<Question6>
WARNING: `makeinfo' is missing on your system. You should only need it if you modified a `.texi' or `.texinfo' file, or any other file indirectly affecting the aspect of the manual. The spurious call might also be the consequence of using a buggy `make' (AIX, DU, IRIX). You might want to install the `Texinfo' package or the `GNU make' package. Grab either from any GNU archive site.
<Question7>
mystery@lcw:~/Downloads/gcc-4.1.0$ makeinfo --version makeinfo (GNU texinfo) 4.13
这里我比较幸运,刚好两步就找到了(修改这个文件也需要权限的哈):
第一步,进入makefile,L_Shift+G,然后搜索/texinfo
第二步,然后再向上搜索?texinfo,好了,就到了上图的位置
然后就开始修改这个用于匹配的正则吧,按图上写的就可以了
Step6
然后再次编译,看着不断变化的字符,慢慢等吧 过了十到二十分钟吧,一屏幕的错误,天啊
/usr/include/dlfcn.h:103: error: expected declaration specifiers or ‘...’ before ‘Dl_info’ /usr/include/dlfcn.h:104: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__THROW’ /usr/include/dlfcn.h:126: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__THROW’ /usr/include/dlfcn.h:176: error: storage class specified for parameter ‘Dl_serpath’ /usr/include/dlfcn.h:184: error: expected specifier-qualifier-list before ‘Dl_serpath’ /usr/include/dlfcn.h:185: error: storage class specified for parameter ‘Dl_serinfo’ /usr/include/dlfcn.h:189: error: expected declaration specifiers before ‘__END_DECLS’ In file included from ../.././gcc/crtstuff.c:92: /usr/include/link.h:35:63: error: bits/elfclass.h: No such file or directory /usr/include/link.h:36:23: error: bits/link.h: No such file or directory In file included from ../.././gcc/crtstuff.c:92: ../.././gcc/crtstuff.c:239: error: storage class specified for parameter ‘__cxa_finalize’ ../.././gcc/crtstuff.c:239: error: weak declaration of ‘__cxa_finalize’ must be public ../.././gcc/crtstuff.c:262: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token ../.././gcc/crtstuff.c:305: error: expected declaration specifiers before ‘asm’ ../.././gcc/crtstuff.c:319: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token ../.././gcc/crtstuff.c:345: error: expected declaration specifiers before ‘asm’ ../.././gcc/crtstuff.c:345: error: old-style parameter declarations in prototyped function definition ../.././gcc/crtstuff.c:345: error: expected ‘{’ at end of input make[2]: *** [crtbegin.o] Error 1 make[2]: Leaving directory `/home/mystery/Downloads/gcc-4.1.0/host-i686-pc-linux-gnu/gcc' make[1]: *** [all-gcc] Error 2 make[1]: Leaving directory `/home/mystery/Downloads/gcc-4.1.0' make: *** [all] Error 2
省略了N行错误啊,找到最后几行
error: old-style parameter declarations in prototyped function definition error: expected ‘{’ at end of input
make之后就是安装了,如果顺利的话make install就过去了
Step8
如果以前有另外版本的gcc,这时只用把新安装的路径链接到gcc就可以了
ln -s /…/gcc-4.1/bin/gcc gcc4 ln -s /…/gcc-4.1/bin/g++ g++4
如果没有的话,就需要自己修改环境变量了
感悟
软件工程出身,对于软件方面来说,自己基础还算不错的,入驻嵌入式,就是对自己提出的一个更高的要求,这个要求就是打通软件和硬件的桥梁,做到一个完整的知识结构体系
因为我并不满足于计算机中的产品,我希望有能改变生活的产品
对于逛论坛这种事,对嵌入式来说,不像软件那么有意义,因为很多东西和自己配置的环境及硬件条件有关,别人的,只能是参考像这整个步骤,书上绝对是一路顺风走过来的
哎,事有轻重缓急,我还有其它事情,这问题就先放在这里了,我先拿cross-3.2的工具用着吧
本文出自 “成鹏致远” 博客,请务必保留此出处http://infohacker.blog.51cto.com/6751239/1174081