【嵌入式】使用Cross Toolchain构建交叉工具链
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
Step7
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
【嵌入式】使用Cross Toolchain构建交叉工具链的更多相关文章
- X86上搭建交叉工具链,来给龙芯笔记本编译本地工具链(未完待续)
故事的背景是,我买了一台龙芯2F的笔记本来装B. 为什么说是装B呢?因为不但操作系统是Linux,而且CPU还是龙芯的. 一般人有这么酷的装备吗?简直是装B大圣啊. 这里一定要申明一点,本人不是IT技 ...
- linux driver ------ 交叉工具链(cross toolchain)
在 ARM Linux 的开发中,人们趋向于使用 Linaro(http://www.linaro.org/)工具链团队维护的 ARM 工具链,它以每月一次的形式发布新的版本,编译好的可执行文件可以网 ...
- 【嵌入式开发】 嵌入式开发工具简介 (裸板调试示例 | 交叉工具链 | Makefile | 链接器脚本 | eclipse JLink 调试环境)
作者 : 韩曙亮 博客地址 : http://blog.csdn.net/shulianghan/article/details/42239705 参考博客 : [嵌入式开发]嵌入式 开发环境 (远 ...
- LFS(Linux From Scratch)构建过程全记录(五):交叉工具链的构建
写在前面 本文将详细讲述如何构建工具链 前置知识 在LFS-BOOK中,我们需要学习一些关于"交叉编译"的内容,详见书本 安装Binutils-2.39 我们cd到sources文 ...
- Buildroot构建指南——工具链
Linux系统的交叉编译工具链用来将源代码变成bin文件或者库文件的一个软件.一般大家默认工具链等于gcc或者arm-linux-gcc,但是实际上,gcc只是工具链的编译器部分,不是全部,制作一个工 ...
- Buildroot构建指南——工具链【转】
本文转载自:http://blog.csdn.net/zhou_chenz/article/details/52346134 Linux系统的交叉编译工具链用来将源代码变成bin文件或者库文件的一个软 ...
- FriendlyARM交叉工具链以及编译第一个arm9应用
不记录什么都会忘光!!!这两天又要用到开发板来做项目,可是好久没有碰了,最近一直在搞上层的东东,对rails和前端感兴趣,我这是不要毕业的节奏了吗?好吧,既然什么都忘光掉了,那就干脆来个痛快,重新装机 ...
- ARM裸机开发之交叉工具链和MakeFile工程管理
一.交叉工具链 嵌入式Linux开发采用交叉开发,简单来说就是在宿主机(PC机)上面编译出能够在其他硬件平台上面运行的程序.在这个过程中,需要用到许多的交叉工具,这些交叉工具的集合就叫做交叉工具链.下 ...
- Ubuntu16.04交叉工具链安装
前言: 开发环境是64位的ubuntu16.04,交叉工具链是通过sudo apt-get install ....安装的,移植uboot2014.10,但是很奇怪,按照网上的介绍在start.s里面 ...
随机推荐
- iOS10 CAAnimationDelegate 的简单适配
1.iOS10中CAAnimationDelegate的警告 原有的工程用xcode8打开编译后,莫名的增加了许多警告,其中关于动画的警告有这样一个,虽然运行后发现并没有什么影响,但还是要探究一下: ...
- Intel Galileo驱动单总线设备(DHT11\DHT22)(转)
Intel Galileo一代的IO翻转速度不够,无法直接驱动单总线设备,二代听说改进了,但没有库,于是国外开发者想出了另一种法子,转过来给大家学习下.如果后面有时间,再来翻译.原文地址:http:/ ...
- webpack window 处理图片和其他静态文件
安装url-loader npm install url-loader --save-dev 配置config文件 { test: /\.(png|jpg)$/, load ...
- App Icon Gear App 图标制作工具
1.App Icon Gear 简介 App Icon Gear(原名 AppIconMaker)不仅可以创建 App 图标.启动图 LaunchImage,还可以生成自定义尺寸的图标集(Image ...
- 【Linux】字符转换命令join
join 看字面上的意义 (加入/参加) 就可以知道,他是在处理两个文件之间的数据,而且,主要是在处理『两个文件当中,有 "相同数据" 的那一行,才将他加在一起』的意思.我们利用底 ...
- 8个实用而有趣Bash命令提示行
很多人都对过命令行提示的重要性不屑一顾,甚至是一点都不关心.但是我却一点都不这么认为,一个好的命令行提示可以改变你使用命令的方式.为此,我在internet上找到一些非常实用,优秀,并有趣的bash的 ...
- 如何学好C、C++语言
如何学好C语言 有人在酷壳的留言版上询问下面的问题 keep_walker : 今天晚上我看到这篇文章. http://programmers.stackexchange.com/questions/ ...
- memcache 与 redis 为web app 带来的性能提升
memcache 与 redis 为web app 带来的性能提升 参考: 1. http://www.cnblogs.com/ToDoToTry/p/3513688.html
- 百度地图 隐藏百度地图Logo
/* 隐藏百度Logo */ .BMap_cpyCtrl, .anchorBL {display: none; }
- fiddler 抓取iphone发出的http和https包
1.清理iphone的描述文件,在通用里面设置.这一步目的防止手机里面已经存在了DO_NOT_TRUST_FiddlerRoot证书,导致后面抓不了包,所以先清理下 2.下载安装fiddler,百度或 ...