1.å¦ä½å¶ä½arm-linux-gccç¼è¯å·¥å
·
2.Linux驱动开发笔记(二):ubuntu系统从源码编译安装gcc7.3.0编译器
3.å¦ä½å®è£
gcc-linaro-arm-linux-gnueabihf-4.8-2014.03
4.å¦ä½å®è£
arm-linux-gcc
5.arm-linux-gcc å arm-elf-gcc çåºå«
6.gcc和arm-linux-gcc是什么关系?区别是什么?
å¦ä½å¶ä½arm-linux-gccç¼è¯å·¥å ·
ä¸ãä¸è½½æºæ件
æºä»£ç æ件åå ¶çæ¬ï¼
binutils-2..tar.bz2, gcc-core-4.4.4.tar.bz2 gcc-g++-4.4.4.tar.bz2 Glibc-2.7.tar.bz2 Glibc-ports-2.7.tar.bz2 Gmp-4.2.tar.bz2 mpfr-2.4.0.tar.bz2mpc-1.0.1.tar.gz Linux-2.6..tar.bz2 ï¼ç±äºæå¨ç¼è¯åºéçè¿ç¨ä¸ï¼æ ¹æ®åºéçä¿¡æ¯ä¿®æ¹äºç¸å ³çC代ç ï¼æ è没æä¸è½½ç¸åºçè¡¥ä¸ï¼
ä¸è¬ä¸ä¸ªå®æ´ç交åç¼è¯å¨æ¶åå°å¤ä¸ªè½¯ä»¶ï¼ä¸»è¦å æ¬bilingualsãccãglibcçãå ¶ä¸ï¼binutils主è¦çæä¸äºè¾ å©å·¥å ·ï¼gccæ¯ç¨æ¥çæ交åç¼è¯å¨ï¼ä¸»è¦çæarm-linux-gcc交åç¼è¯å·¥å ·ï¼èglibc主è¦æä¾ç¨æ·ç¨åºæéè¦çä¸äºåºæ¬å½æ°åºã
äºã建ç«å·¥ä½ç®å½
ç¼è¯æç¨ä¸»æºåå· fc.iï¼èææºéçæ¯VM7.0ï¼Linuxåè¡çéçæ¯Fedora9,
第ä¸æ¬¡ç¼è¯æ¶ç¨çæ¯rootç¨æ·ï¼ç¬¬äºæ¬¡ç¨ä¸è¬ç¨æ·yyzï¼, ææçå·¥ä½ç®å½é½å¨/home/yyz/crossä¸é¢å»ºç«å®æï¼é¦å å¨/home/yyzç®å½ä¸å»ºç«crossç®å½ï¼ç¶åè¿å ¥å·¥ä½ç®å½ï¼æ¥çå½åç®å½ãå½ä»¤å¦ä¸ï¼
åå»ºå·¥å ·é¾æ件夹ï¼
[root@localhost cross]# mkdir embedded-toolchains
ä¸é¢å¨æ¤æ件夹ä¸å»ºç«å¦ä¸å 个ç®å½ï¼
setup-dirï¼åæ¾ä¸è½½çå缩å ï¼
src-dirï¼åæ¾binutilsãgccãglibc解åä¹åçæºæ件ï¼
Kernelï¼åæ¾å æ ¸æ件ï¼å¯¹å æ ¸çé ç½®åç¼è¯å·¥ä½ä¹å¨æ¤å®æï¼
build-dir ï¼ç¼è¯src-dirä¸é¢çæºæ件ï¼è¿æ¯GNUæ¨èçæºæ件ç®å½ä¸ç¼è¯ç®å½å离çåæ³ï¼
tool-chainï¼äº¤åç¼è¯å·¥å ·é¾çå®è£ ä½ï¼
programï¼åæ¾ç¼åç¨åºï¼
doc:说æææ¡£åèæ¬æ件ï¼
ä¸é¢å»ºç«ç®å½ï¼å¹¶æ·è´æºæ件ã
[root@localhost cross] #cd embedded- toolchains
[root@localhost embedded- toolchains] #mkdir setup-dir src-dir kernel build-dir tool-chain program doc
[root@localhost embedded- toolchains] #ls
build-dir doc kernel program setup-dir src-dir tool-chain
[root@localhost embedded- toolchains] #cd setup-dir
æ·è´æºæ件ï¼
è¿éæ们éç¨ç´æ¥æ·è´æºæ件çæ¹æ³ï¼é¦å åºè¯¥ä¿®æ¹setup-dirçæé
[root@localhost embedded- toolchains] #chmod setup-dir
ç¶åç´æ¥æ·è´/home/yyzç®å½ä¸çæºæ件å°setup-dirç®å½ä¸ï¼å¦ä¸å¾ï¼
建ç«ç¼è¯ç®å½ï¼
[root@localhost setup-dir] #cd ../build-dir
[root@localhost build -dir] #mkdir build-binutils build-gcc build-glibc
ä¸ãè¾åºç¯å¢åé
è¾åºå¦ä¸çç¯å¢åéæ¹ä¾¿æ们ç¼è¯ã
为ç®åæä½è¿ç¨ãä¸é¢å°±å»ºç«shellå½ä»¤èæ¬environment-variablesï¼
[root@localhost build -dir] #cd ../doc
[root@localhost doc] #mkdir scripts
[root@localhost doc] #cd scripts
ç¨ç¼è¾å¨viç¼è¾ç¯å¢åéèæ¬envionment-variablesï¼[root@localhost scripts]
#vi envionment-variables
export PRJROOT=/home/yyz/cross/embedded-toolchains
export TARGET=arm-linux
export PREFIX=$PRJROOT/tool-chain
export TARGET_PREFIX=$PREFIX/$TARGET
export PATH=$PREFIX/bin:$PATH
æªå¾å¦ä¸ï¼
æ§è¡å¦ä¸è¯å¥ä½¿ç¯å¢åéçæï¼
[root@localhost scripts]# source ./environment-variables
åã建ç«äºè¿å¶å·¥å ·ï¼binutilsï¼
ä¸é¢å°åæ¥ä»ç»å®è£ binutils-2..1çè¿ç¨ã
[root@localhost script] # cd $PRJROOT/src-dir
[root@localhost src-dir] # tar jxvf ../setup-dir/binutils-2..1.tar.bz2
[root@localhost src-dir] # cd $PRJROOT/build-dir/build-binutils
å建Makefileï¼
[root@localhost build-binutils] #../../src-dir/binutils-2..1/configure --target=$TARGET --prefix=$PREFIX
å¨build-binutilsç®å½ä¸é¢çæMakefileæ件ï¼ç¶åæ§è¡makeï¼make install,æ¤è¿ç¨æ¯è¾ç¼æ ¢ï¼å¤§çº¦éè¦ä¸ä¸ªåéå·¦å³ãå®æåå¯ä»¥å¨$PREFIX/binä¸é¢çå°æ们çæ°çbinutilã
è¾å ¥å¦ä¸å½ä»¤
[root@localhost build-binutils]#ls $PREFIX/bin
Linux驱动开发笔记(二):ubuntu系统从源码编译安装gcc7.3.0编译器
在编译Ubuntu驱动时,由于使用的gcc版本为7.3.0,通过apt管理和下载都无法直接安装,因此需要从源码编译安装gcc7.3.0编译器。
GCC,作为GNU项目的bias突破公式源码重要组成部分,是一款遵循GPL许可证的自由软件。起初,它为GNU操作系统设计,如今已广泛应用于Linux、BSD、MacOS X等系统,甚至在Windows上也有应用。GCC支持多种处理器架构,如x、ARM和MIPS,并且支持多种编程语言,如何使用html源码如C、C++、Fortran、Pascal等。
要从源码安装gcc7.3.0,首先需要下载源码包。下载地址为:mirrors.tuna.tsinghua.edu.cn...
安装过程分为几个步骤。首先,抄底线指标源码确保网络连接,因为需要依赖库,如libgmp-dev、libmpfr-dev和libmpc-dev。安装完这些后,不要卸载已有的gcc,因为可能会遇到问题。
下载并解压gcc-7.3.0.tar.gz,商城网源码分享然后执行./configure。注意增加c和c++的配置,避免编译结果只有g++。配置完成后,进行make -j4编译,可能会遇到错误,如"fatal error: asm/errno.h: No such file or directory",这时需要修改头文件路径。AG棋牌游戏源码
继续编译,可能会遇到"sanitizer_syscall_generic.inc::: error: '__NR_open' was not declared in this scope",解决方法是修正头文件链接。最后,编译成功后执行sudo make install,并确认安装版本。
在安装过程中,有两点需要注意:一是本地需要g++,否则编译时会出错,解决方法是安装gcc;二是安装后可能只有g++,没有gcc,此时需在./configure阶段添加c和c++的配置。
å¦ä½å®è£ gcc-linaro-arm-linux-gnueabihf-4.8-.
1ã å¦æè¦èªå·±ç¼è¯å·¥å ·é¾ï¼ä»ä»¥ä¸é¾æ¥ä¸è½½æºç
crosstools-ngä¸è½½å°å
monly used with uClinux. uC-libc and
uClibc. They are quite different despite their similar names. Here is a
quick overview of how they are different.
ããuC-libc is the original library for uClinux. It was based on sources
from the Linux- C library which was part of the ELKs project with m
support added by Jeff Dionne and Kenneth Albanowski. It is a fairly complete
libc implementation, however, some of the API's are a little non-standard
and quite a few common libc routines are not present. Currently it has
stable support for m, ColdFire and ARM (Non-MMU) architectures. It was
primary design goal is to be small and light weight. It does try to conform
to any standards, although its API tries to be compatible with most libcs,
it is not always exactly the same.
ããThe uClinux distribution provides an environment that can compile using
either uC-libc or uClibc depending on your needs. For m and Coldfire
platforms it is generally better to chose uC-libc as it supports shared
libraries and is the most commonly used libc for these CPUs. uClibc also
works quite well with almost all platforms supported by the distribution.
Which libc you choose to use will be decided by your requirements
uClinuxæ两个ç»å¸¸ä½¿ç¨çlibcåºï¼uC-libcåuClibcãè½ç¶ä¸¤è ååå¾ç¸ä¼¼ï¼å ¶å®æå·®
å«ï¼ä¸é¢å°±ç®åçä»ç»ä¸ä¸äºè çä¸åä¹å¤ãuC -libcæ¯ææ©ä¸ºuClinuxå¼åçåºï¼æ¯
Jeff DionneåKenneth Albanowski为å¨EKLs项ç®ä¸æ¯æmå¨Linux- Cåºæºç
ä¸ç§»æ¤çãuC-libcæ¯ä¸ä¸ªå®å ¨çlibcå®ç°ï¼ä½å ¶ä¸æä¸äºapiæ¯éæ åçï¼æäºlibcç
æ åä¹æ²¡æå®ç°ãuC-libc稳å®å°æ¯æ mï¼ColdFireå没æMMUçARMãå ¶ä¸»è¦è®¾è®¡
ç®æ æ¯âå°âã"è½»"ï¼å¹¶å°½éä¸æ åä¸è´ï¼è½ç¶å®çAPIåå¾å¤libcå ¼å®¹ï¼ä½æ¯ä¼¼ä¹å¹¶
ä¸åå®ææçé£æ ·åæææ åä¸è´ã
uClibcå°±æ¯ä¸ºäºè§£å³è¿ä¸ªé®é¢ä»uC-libcä¸åå±åºæ¥çãå®çææAPIé½æ¯æ åç(æ£ç¡®
çè¿åç±»åï¼åæ°çç)ï¼å®å¼¥è¡¥äºuC-libcä¸æ²¡æå®ç°çlibcæ åï¼ç°å¨å·²ç»è¢«ç§»æ¤å°
å¤ç§æ¶æä¸ãä¸è¬æ¥è®²ï¼å®å°½éå ¼å®¹glibc以便使åºç¨ç¨åºç¨uClibcæ¹ååç容æã
uClibcè½å¤å¨æ åç VM linuxåuClinuxä¸é¢ä½¿ç¨ã为äºåºç¨ç¨åºçç®æ´ï¼å®çè³å¯ä»¥
å¨è®¸å¤æ¯æMMUçå¹³å°ä¸è¢«ç¼è¯æå ±äº«åºãErik Andersonå¨uClibcèååäºå¾å¤çå·¥
ä½ãuClibcæ¯æ许å¤ç³»åçå¤çå¨ï¼mï¼Coldfireï¼ARMï¼MIPSï¼vï¼ xï¼
iï¼Sparcï¼SuperHï¼Alphaï¼PowerPCåHitachi 8ãä¸æå¢å çå¹³å°æ¯ææ¾ç¤ºuClibc
è½å¤å¾å®¹æçéåºæ°çæ¶æãuClinuxåè¡çæä¾äºç¯å¢è½å¤è®©ä½ éæ©ä½¿ç¨uC-libcææ¯
uClibcç¼è¯ã对äºmåColdfireå¹³å°æ¥è¯´ï¼éæ©uC-libcè¿æ¯ç¨å¾®å¥½ä¸ç¹ï¼å 为å®
æ¯æå ±äº«åºï¼èå ±äº«åºæ¯è¿äºcpuç»å¸¸ä½¿ç¨ç libc.uClibcä¹å ä¹åææçå¹³å°é½è½å¾
好çå·¥ä½ãéæ©åªç§libcåå³äºä½ çéæ±ã
newlib æ¯ä¸ä¸ªç¨äºåµå ¥å¼ç³»ç»çå¼æ¾æºä»£ç çCè¯è¨ç¨åºåºï¼ç±libcålibm两个åºç»
æï¼ç¹ç¹æ¯è½»é级ï¼é度快ï¼å¯ç§»æ¤å°å¾å¤CPUç»æä¸ãnewlibå®ç°äºè®¸å¤å¤æçå
è½ï¼å æ¬å符串æ¯æï¼æµ®ç¹è¿ç®ï¼å ååé (å¦malloc)åI/Oæµå½æ°(printfï¼fprinf()
çç)ãå ¶ä¸libcæä¾äºc è¯è¨åºçå®ç°ï¼èlibmæä¾äºæµ®ç¹è¿ç®æ¯æã
å¨ä¸ºARM交åç¼è¯gccç¼è¯å¨æ¶ï¼å¯¹gccæå®ä¸åçé ç½®é项æ¶ï¼ä½¿ç¨çCè¯è¨åºå°±ä¸åï¼
gccç¼è¯å¨é»è®¤ä½¿ç¨Glibcï¼ä¹å¯ä»¥ä½¿ç¨ uClibc/uC-libc(åºæ¬å ¼å®¹Glibc API)ï¼å½ä½¿ç¨
--with-newlibæ¶ï¼gccç¼è¯å¨ä¸ä½¿ç¨Glibcãå½æ²¡æ交åç¼è¯Glibcæ¶ï¼å¯ä»¥ä½¿ç¨
--with-newlibç¦æ¢è¿æ¥Glibcèç¼è¯bootstrap gccç¼è¯å¨ãä»gccæºç®å½ä¸ç
config/armä¸çt-linuxåt-arm-elfä¸å¯ä»¥çåºï¼ä¸åç--targetä¹å½±ågccè¿æ¥Cè¯è¨
åºï¼t-linux(--target=arm-linux)é»è®¤ä½¿ç¨Glibcï¼-arm-elf(--target=arm-elf)使ç¨
- Dinhibit_libcç¦æ¢è¿æ¥Glibcï¼è¿æ¶æ们就å¯ä»¥ä½¿ç¨newlibçå ¶ä»Cè¯è¨åºç¼è¯GCCå·¥
å ·é¾ã
è½ç¶GCCå·¥å ·é¾é ç½®äºä¸åççCè¯è¨åºï¼ä½ç±äºè¿äºCè¯è¨åºé½å¯ä»¥ç¨æ¥æ¯æGCCï¼å®ä»¬
å¯¹æ ¸å¿æ°æ®çå¤çä¸ä¸åå¨è¾å¤§åºå ¥ãå èarm-linux-* å arm-elf-*åºå«ä¸»è¦è¡¨ç°å¨
Cè¯è¨åºçå®ç°ä¸ï¼ä¾å¦ä¸åç³»ç»è°ç¨ï¼ä¸åçå½æ°éå®ç°ï¼ä¸åçABI\å¯å¨ä»£ç 以å
ä¸åç³»ç»ç¹æ§çå¾®å°çå·®å«ã
arm-linux-*å arm-elf-*ç使ç¨æ²¡æä¸ä¸ªç»å¯¹çæ åï¼æé¤ä¸ååºå®ç°çå·®å¼ï¼gccå¯
以ç¼è¯ä»»ä½ç³»ç»ãarm-linux-*å arm-elf-*é½å¯ä»¥ç¨æ¥ç¼è¯è£¸æºç¨åºåæä½ç³»ç»ï¼åª
æ¯å¨éµå¾ªä¸é¢çæè¿°æ¶ç³»ç»ç¨åºæ¾å¾æ´å åè°ï¼
arm-linux-*é对è¿è¡linuxçARMæºå¨ï¼å ¶ä¾èµäºæå®çCè¯è¨åºGlibcï¼å 为åæ ·ä½¿ç¨
Glibcçlinuxè使å¾arm-linux-*å¨è¿è¡linuxçARMæºå¨ä¸ç¼è¯æ¾å¾æ´å åè°ã
arm-elf-*åæ¯ä¸ä¸ªç¬ç«çç¼è¯ä½ç³»ï¼ä¸ä¾èµäºæå®çCè¯è¨åºGlibcï¼å¯ä»¥ä½¿ç¨newlib
çå ¶ä»Cè¯è¨åºï¼ä¸è¦æ±æä½ç³»ç»æ¯æï¼å½å ¶ä½¿ç¨ä¸ºåµå ¥å¼ç³»ç»è设计çä¸äºè½»å·§çCè¯
è¨åºæ¶ç¼è¯è£¸æºç¨åº(没ælinuxç大åæä½ç³»ç»çç¨åº)ï¼å¦çæ§ç¨åºï¼bootloaderç
è½ä½¿å¾ç³»ç»ç¨åºæ´å å°å·§å¿«æ·ã
Linaro prebuilt toolchain does support both hard and soft floating
point. You can get it from /linaro-toolchain-binaries/+milestone/. try: ./arm-linux-gnueabihf-gcc -print-multi-lib
The default configure is --with-arch=armv7-a --with-tune=cortex-a9
--with-fpu=vfpv3-d --with-float=hard --with-mode=thumb
To use soft floating, you need options: -marm -march=armv4t -mfloat-abi=soft.
In your case, please try to change -march=armv5 to "-march=armv4t"
If you want to change to configure to cortex-a8 and armv5. You need
* Change cortex-a9 to cortex-a8 in
samples/linaro-arm-linux-gnueabihf/crosstool.config
* Change armv4t to armv5 in
contrib/linaro/patches/gcc/linaro-4.7-./multilib.patch,
Then follow the instructions to rebuild the toolchain
(contrib/linaro/doc/README.txt)
BTW: crosstool-ng-linaro does not support multilib for eglibc. It uses
the prebuilt sysroot from Ubuntu Precise. If it does not work for you,
please use the latest crosstool-ng from http://crosstool-ng.org/.
gcc和arm-linux-gcc是什么关系?区别是什么?
gcc是linux系统下面用来将代码编译成一个可执行程序的手段。编译出来的是适用于linux系统的可执行二进制文件。可执行程序其实就是一堆的二进制机器码。这些机器码代表什么含义只有机器本身能理解。所以你用gcc编译出来的可执行程序只有在linux系统下面可以运行。举个例子你的可执行程序里面有一句.这句在linux下面可能是吃饭的意思,但是在windows下面可能是撒尿的意思。那你说linux的可执行程序放在window下面能正常运行吗?肯定不能嘛。你要的目的是吃饭,它帮你执行撒尿很显然就不对了。同样的可能在ARM下面的意思是睡觉。不同系统的机器码含义是不一样的。所以你在linux系统下面写的代码要怎样才能在ARM系统上面跑呢。这就需要用到交叉编译。arm-linux-gcc是什么意思?就是告诉你的编译器,我编写的环境是linux,但是我希望生成的可执行程序是在arm上面跑的。这就是交叉编译。编写环境和执行环境分离的一种手段。