Preface
前面编译linux内核的时候,用各种cross版本都不行啊,真是纠结,于是就想着自己也要会编译交叉工具的方法,然后各种尝试,各种问题啊,最后还是没解决(还有其它事情),步骤我都走熟了,记下来吧
Preparation
|
1
2
3
4
5
|
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
Step1当然是解压crosstool-0.42.tar.gzStep2我们需要自己配置文件,我取名为arm.sh< arm.sh>
123456789101112#!/bin/shset-exTARBALLS_DIR=/home/mystery/cross_toolchain/crossTools# 定义工具链源码所存放位置。RESULT_TOP=/opt/crosstool# 定义工具链的安装目录exportTARBALLS_DIR RESULT_TOPGCC_LANGUAGES="c,c++"# 定义支持C, C++语言exportGCC_LANGUAGES# 创建/opt/crosstool目录mkdir-p $RESULT_TOP# 编译工具链,该过程需要数小时完成。eval'cat arm.dat gcc-4.1.0-glibc-2.3.2.dat'sh all.sh --notestechoDone.
Step3
我们还需要改二个配置文件gcc-4.1.0-glibc-2.3.2.dat与arm.dat,这个根据自己下载的文件需要来改
1234567<gcc-4.1.0-glibc-2.3.2.dat>BINUTILS_DIR=binutils-2.15GCC_DIR=gcc-3.3.6GLIBC_DIR=glibc-2.3.2GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.2LINUX_DIR=linux-2.6.14LINUX_SANITIZED_HEADER_DIR=linux-libc-headers-2.6.12.0
<arm.dat>
123KERNELCONFIG='pwd'/arm.config# 内核的配置TARGET=arm-linux-# 编译生成的工具链名称TARGET_CFLAGS="-O"# 编译选项
Step4
执行脚本,将Crosstool的脚本文件和配置文件准备好之后,开始执行arm.sh脚本来编译交叉编译工具。如果顺利的话,这步经过数个小时后,就能生成交叉编译工具了,数个小时啊,准备迎接各种error吧
<Question1>
123+ abort Don't run all.sh or crosstool.sh as root, it's dangerous+echoDon't run all.sh or crosstool.sh as root, it's dangerousDon't run all.sh or crosstool.sh as root, it's dangerous
<Solution>:这脚本够纠结的,用普通帐户时,执行命令又权限不够,用root帐户,又不让你运行,那么
不用root帐户又有权限的办法就是chmod,自己给自己权限吧,我是chmod+chgrp+chown都改了
<Question2>
|
1
2
3
4
5
6
|
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
|
Solution: 还是权限问题,opt目录是存放第三软件的目录,在这个目录下进行写操作需要root权限, 但是又不能用root执行,和前面一样,自己给自己权限吧,我也是chgrp+chown+chmod都用了
123456789101112131415161718192021mystery@lcw:/opt$ls-ltotal 36drwxr-xr-x 2 root root 4096 Apr 7 20:26 crosstooldrwxrwsr-x 9 messagebususers4096 Feb 25 12:39 eclipsedrwxr-xr-x 3 root root 4096 Apr 4 10:47 googledrwxr-xr-x 8 500 500 4096 Mar 1 19:36 jdk1.7.0_17drwxr-xr-x 3 root root 4096 Apr 4 11:25 kingsoftdrwx------ 2 root root 16384 Apr 4 09:32 lost+foundmystery@lcw:/opt$chgrpmystery crosstool/chgrp: changing group of `crosstool/': Operation not permittedmystery@lcw:/opt$sudochgrpmystery crosstool/[sudo] passwordformystery:mystery@lcw:/opt$sudochownmystery crosstool/mystery@lcw:/opt$ls-ltotal 36drwxr-xr-x 2 mystery mystery 4096 Apr 7 20:26 crosstooldrwxrwsr-x 9 messagebususers4096 Feb 25 12:39 eclipsedrwxr-xr-x 3 root root 4096 Apr 4 10:47 googledrwxr-xr-x 8 500 500 4096 Mar 1 19:36 jdk1.7.0_17drwxr-xr-x 3 root root 4096 Apr 4 11:25 kingsoftdrwx------ 2 root root 16384 Apr 4 09:32 lost+found
<Question3>
|
1
2
3
|
/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:这种是最简单的,缺什么装什么,不过最好把这个记一下,不然以后装多了,你都不知道自己电脑上装了些什么
1mystery@lcw:~/cross_toolchain/crosstool-0.43$sudoapt-getinstallbison
<Question4>
12oss_toolchain/crosstool-0.43/crosstool.sh: flex: not foundcrosstool: You don't have flex installed
solution:同上
1mystery@lcw:~/cross_toolchain/crosstool-0.43$sudoapt-getinstallflex
<Question5>
12345678910checkingforpwd.../bin/pwdcheckingforarm-linux-gcc... gccchecking version of gcc... 4.6.3, badcheckingforgnumake... nocheckingforgmake... nocheckingformake...makechecking version ofmake... 3.81, okconfigure: error:*** These critical programs are missing or too old: gcc*** Check the INSTALLfileforrequired versions意思是说,我系统的GCC版本太高了(4.6.3,目录最高版本,也是系统默认版本),版本太高了也不好啊,由于crosstools最后只支持gcc-4.1.0版本的,那我去下个GCC-4.1.0的吧。换了几个源,都没有找到4.1的,只好去网上找了
然后就开始发装,各种依赖关系啊,各种装不上
1234567891011121314151617181920212223242526mystery@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 compilerun 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 compilerri gcc-4.6-base 4.6.3-1ubuntu5 GCC, the GNU Compiler Collection (base packaun 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 libraryun libgcc1-dbg <none> (no description available)
最多装上了gcc-4.1,及base,后面因为依赖关系涉及到lib和libgcc,看网上说的,如果直接完全卸载
这些东西可能会导致系统出错, 纠结,那就老老实实地下个gcc-4.1.0的源码编译吧
Step5
解压gcc-4.1.0的源码,然后执行
1mystery@lcw:~/Downloads$# ./configure --prefix=/opt/gcc-4.1&& make
这里我也是将gcc安装到opt目录下的,相应权限问题如上面一样解决,还有新的问题等着呢
<Question6>
123456WARNING: `makeinfo' is missing on your system. You should only need itifyou modified a `.texi' or `.texinfo'file, or any otherfileindirectly affecting the aspect of the manual. The spuriouscall might also be the consequence of using a buggy `make' (AIX,DU, IRIX). You might want toinstallthe `Texinfo' package orthe `GNUmake' package. Grab either from any GNU archive site.
solution: 系统不包含“makeinfo”,好吧,安装就是了嘛。安装之后,再次编译,仍然如此,纠结了,老规矩,百度解决不了,找谷歌(身边没人玩这个啊。。。。。)
<Question7>
原来是版本问题,不能识别
12mystery@lcw:~/Downloads/gcc-4.1.0$ makeinfo --versionmakeinfo (GNU texinfo) 4.13系统只支持4.2~4.9的版本,我4.13的版本,当然不支持啦solution: 这个makeinfo的调用主要是在makefile里面实现的,现在我们需要在makefile里面找到这行代码然后改正过来
如上所示,makefile是通过扩展的正则表达式来匹配的(关于正则表达式,这里就不多说了啊),但是细心的朋友会看到,三千多行啊,其实这还没到这个文件的中间部分呢,怎么找呢?这里我比较幸运,刚好两步就找到了(修改这个文件也需要权限的哈):
第一步,进入makefile,L_Shift+G,然后搜索/texinfo
第二步,然后再向上搜索?texinfo,好了,就到了上图的位置
然后就开始修改这个用于匹配的正则吧,按图上写的就可以了
Step6
然后再次编译,看着不断变化的字符,慢慢等吧 过了十到二十分钟吧,一屏幕的错误,天啊
123456789101112131415161718192021222324/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 specifiedforparameter ‘Dl_serpath’/usr/include/dlfcn.h:184: error: expected specifier-qualifier-list before ‘Dl_serpath’/usr/include/dlfcn.h:185: error: storage class specifiedforparameter ‘Dl_serinfo’/usr/include/dlfcn.h:189: error: expected declaration specifiers before ‘__END_DECLS’Infileincluded from ../.././gcc/crtstuff.c:92:/usr/include/link.h:35:63: error: bits/elfclass.h: No suchfileor directory/usr/include/link.h:36:23: error: bits/link.h: No suchfileor directoryInfileincluded from ../.././gcc/crtstuff.c:92:../.././gcc/crtstuff.c:239: error: storage class specifiedforparameter ‘__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 declarationsinprototypedfunctiondefinition../.././gcc/crtstuff.c:345: error: expected ‘{’ at end of inputmake[2]: *** [crtbegin.o] Error 1make[2]: Leaving directory `/home/mystery/Downloads/gcc-4.1.0/host-i686-pc-linux-gnu/gcc'make[1]: *** [all-gcc] Error 2make[1]: Leaving directory `/home/mystery/Downloads/gcc-4.1.0'make: *** [all] Error 2
省略了N行错误啊,找到最后几行
12error: old-style parameter declarationsinprototypedfunctiondefinitionerror: expected ‘{’ at end of input
这个错误以前在电脑上代码时也遇见过,应该就是哪里少写了分号或者半角和全角的格式没有对这是指这个源代码中有error吗?天啊,我是没那个能力在这里面去翻了,也没有时间啊,事情还多着呢。。。下面的步骤就有时间再验证吧
Step7make之后就是安装了,如果顺利的话make install就过去了
Step8
如果以前有另外版本的gcc,这时只用把新安装的路径链接到gcc就可以了
12ln-s /…/gcc-4.1/bin/gccgcc4ln-s /…/gcc-4.1/bin/g++ g++4如果没有的话,就需要自己修改环境变量了
感悟
这就是自学啊,遇到任何问题的时候,我身边根本没有人能和我讨论这方面的东西,这样有好处,也有坏处, 好处当然是:锻炼自学能力和解决问题的能力, 缺点就是:周期太长了啊
不过很无奈的说:我也不想这样软件工程出身,对于软件方面来说,自己基础还算不错的,入驻嵌入式,就是对自己提出的一个更高的要求,这个要求就是打通软件和硬件的桥梁,做到一个完整的知识结构体系
因为我并不满足于计算机中的产品,我希望有能改变生活的产品
开学的时候,我和老师请假去参加培训,但是因为才大三,老师不让我走,硬性条件让我只能再次自学……对于逛论坛这种事,对嵌入式来说,不像软件那么有意义,因为很多东西和自己配置的环境及硬件条件有关,别人的,只能是参考像这整个步骤,书上绝对是一路顺风走过来的出现问题了,百度一下,你遇到的问题,别人也遇到过,但是同样的问题,别人的解决方法,却不一定也适合你,就这么简单哎,事有轻重缓急,我还有其它事情,这问题就先放在这里了,我先拿cross-3.2的工具用着吧记录里面也有一些问题的解决方法,算是教训吧
本文转自infohacker 51CTO博客,原文链接:
http://blog.51cto.com/liucw/1174081
