【嵌入式】使用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 ifyou modified a `.texi' or `.texinfo' file, or any other fileindirectly affecting the aspect of the manual. The spuriouscall might also be the consequence of using a buggy `make' (AIX,DU, IRIX). You might want to install the `Texinfo' package orthe `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
转载于:https://www.cnblogs.com/lcw/p/3159427.html
【嵌入式】使用Cross Toolchain构建交叉工具链相关推荐
- 【嵌入式开发】 嵌入式开发工具简介 (裸板调试示例 | 交叉工具链 | Makefile | 链接器脚本 | eclipse JLink 调试环境)
作者 : 韩曙亮 博客地址 : http://blog.csdn.net/shulianghan/article/details/42239705 参考博客 : [嵌入式开发]嵌入式 开发环境 (远程 ...
- Buildroot构建指南——工具链
Linux系统的交叉编译工具链用来将源代码变成bin文件或者库文件的一个软件.一般大家默认工具链等于gcc或者arm-linux-gcc,但是实际上,gcc只是工具链的编译器部分,不是全部,制作一个工 ...
- linux centos7 使用 crosstool-ng 构建 交叉编译 工具链 即构建各cpu架构平台的gcc编译器
简介 crosstool-ng,全称是crosstool Next Generation,即下一代crosstool.crosstool是个交叉编译器的制作工具,但是做的不够好,于是有人(Yann E ...
- crosstool-ng 交叉工具链默认配置 名词解释
crosstool-ng默认配置列表 crosstool-ng版本1.23.0 安装使用参考 centos7用crosstool-ng构建交叉工具编译链 https://blog.csdn.net/w ...
- 交叉编译知识解析(一) —— 交叉编译和交叉工具链
一.交叉编译简介 1.什么是交叉编译 1.1 本地编译 解释什么是交叉编译之前,先要明白一个概念:本地编译 我们之前常见的软件开发,都是属于本地编译:在当前的PC下,x86的CPU下,直接编译出来程序 ...
- 【嵌入式系统开发】学习笔记四:嵌入式开发的基本概念与工具链
提示:本文内容参考慕课课程:<ARM微控制器与嵌入式系统> 嵌入式开发的基本概念与工具链 前言 一.电路板 1.开发板:EVB(Evaluation board) 2.最小系统板 二.开发 ...
- arm-buildroot-linux-,buildroot构建交叉编译工具链,根文件系统
支持多种处理器,arch,avr32,mips,x86等等,在arch/目录可查看. buildroot可使用make menuconfig进行配置,选择需要编译到目标文件系统的包,相关的配置文件在c ...
- arm-linux-gcc 裸机程序,Linux下ARM裸机开发-交叉工具链
初识linux下ARM的裸机开发全过程.现在总结如下: 首先说明为什么要学习裸机开发,一方面bootloader的编写要用到裸机开发的知识,另一方面就是驱动的开发.一般情况下我们进行的系统上的开发. ...
- 【编译原理】交叉工具链详解
1.嵌入式开发模型-交叉开发 在嵌入式开发过程中有宿主机和目标机的角色之分,宿主机是执行编译.链接嵌入式软件的计算机,目标机是运行嵌入式软件的硬件平台.在宿主机执行编译的流程如下: 而所谓的交叉编译就 ...
最新文章
- 半年时间学linux,你学Linux入门用了多长时间?
- AgileEAS.NET平台应用开发教程-案例计划
- python opencv cv2.imdecode()函数(从内存中的缓冲区读取图像)
- C++构造函数语意学
- 崛起于Springboot2.X之Mongodb多数据源处理(35)
- 研究生计划 三
- python3 super_Python super()– Python 3 super()
- C++ 从入门到入土(English Version)Section5: Real numbers + bitwise operations
- 我在这战斗的一年里(阎阳生)
- 菜鸟python实例_菜鸟学Python,双手奉上老司机给上路新手总结的Python实战问题…...
- 典型相关分析 CCA
- 家庭多房间网线连接---小白快速上手
- 【信源编码技术】实验1-浊音清音爆破音的时域及频域特性分析
- 谈谈亲历的WMS、MES与ERP的集成之路
- 学习四旋翼(三):DMP姿态解算和串级PID控制姿态
- ETest半实物仿真测试在汽车电子电器系统中的应用
- Python爬虫学习(十一)下载验证码图片
- 【硬核】 ROS Navigation 局部路径规划常见算法
- 各大厂面经分享:Java全栈知识+1500道大厂面试真题
- Android中的加密方法
热门文章
- 统一建模语言UML轻松入门之用例
- ES6学习(七)—Set 和 Map 数据结构
- JavaScript学习(二十七)—解决IE以及IE8之前的浏览器下面的添加事件或者删除事件
- html5特效 手机震动,html5 可以让用户按一下手机键盘手机震动一下吗
- android ndk 多线程mk,Android NDK 开发教程六: application.mk
- 滴滴为什么接不到长途单?
- 理财产品收益可以保证吗?
- 存量累计超20亿部“宁闲不卖”如何“唤醒”依旧有经济价值的旧手机?
- 感觉小轿车要比SUV舒服,为什么很多人还是选择了SUV?
- 准备结婚,大家买的三金都有哪些?