1.å¦ä½ä¸ºåµå
¥å¼å¼å建ç«äº¤åç¼è¯ç¯å¢
2.GCC编译工具链(更新中)
3.å¦ä½å¶ä½arm-linux-gccç¼è¯å·¥å
·
4.Linuxä¸ç交åç¼è¯ç¯å¢è®¾ç½®
å¦ä½ä¸ºåµå ¥å¼å¼å建ç«äº¤åç¼è¯ç¯å¢
ããä¸é¢æ们å°ä»¥å»ºç«é对armç交åç¼è¯å¼åç¯å¢ä¸ºä¾æ¥è§£è¯´æ´ä¸ªè¿ç¨ï¼å ¶ä»çä½ç³»ç»æä¸è¿ä¸ªç¸ç±»ä¼¼ï¼åªè¦ä½ä¸äºå¯¹åºçæ¹å¨ãæçå¼åç¯å¢æ¯ï¼å®¿ä¸»æº i-redhat-7.2ï¼ç®æ æº armã
ããè¿ä¸ªè¿ç¨å¦ä¸
ãã1. ä¸è½½æºæ件ãè¡¥ä¸å建ç«ç¼è¯çç®å½
ãã2. 建ç«å æ ¸å¤´æ件
ãã3. 建ç«äºè¿å¶å·¥å ·ï¼binutilsï¼
ãã4. 建ç«åå§ç¼è¯å¨ï¼bootstrap gccï¼
ãã5. 建ç«cåº(glibc)
ãã6. 建ç«å ¨å¥ç¼è¯å¨ï¼full gccï¼
ããä¸è½½æºæ件ãè¡¥ä¸å建ç«ç¼è¯çç®å½
ãã1. éå®è½¯ä»¶çæ¬å·
ããéæ©è½¯ä»¶çæ¬å·æ¶ï¼å ççglibcæºä»£ç ä¸çINSTALLæ件ãé£éå举äºè¯¥çæ¬çglibcç¼è¯æ¶æéçbinutils ågccççæ¬å·ãä¾å¦å¨ glibc-2.2.3/INSTALL æ件ä¸æ¨è gcc ç¨ 2.以ä¸ï¼binutils ç¨ 2..1 以ä¸çæ¬ã
ããæéçå个软件ççæ¬æ¯ï¼
ããlinux-2.4.+rmk2
ããbinutils-2..1
ããgcc-2..3
ããglibc-2.2.3
ããglibc-linuxthreads-2.2.3
ããå¦æä½ éçglibcççæ¬å·ä½äº2.2ï¼ä½ è¿è¦ä¸è½½ä¸ä¸ªå«glibc-cryptçæ件ï¼ä¾å¦glibc-crypt-2.1.tar.gzã Linux å æ ¸ä½ å¯ä»¥ä»www.kernel.org æå®çéåä¸è½½ã
ããBinutilsãgccåglibcä½ å¯ä»¥ä»FSFçFTPç«ç¹ftp://ftp.gun.org/gnu/ æå®çéåå»ä¸è½½ã å¨ç¼è¯glibcæ¶ï¼è¦ç¨å° Linux å æ ¸ä¸ç include ç®å½çå æ ¸å¤´æ件ãå¦æä½ åç°æåé没æå®ä¹è导è´ç¼è¯å¤±è´¥ï¼ä½ å°±æ¹åä½ çå æ ¸çæ¬å·ãä¾å¦æå¼å§ç¨linux-2.4.+vrs2ï¼ç¼è¯glibc-2.2.3 æ¶æ¥ BUS_ISA 没å®ä¹ï¼åæ¥åç°å¨ 2.4. å¼å§å®çåå被æ¹ä¸º CTL_BUS_ISAãå¦æä½ æ²¡æå®å ¨çææ¡ä¿è¯ä½ æ¹çå æ ¸æ¹å®å ¨äºï¼å°±ä¸è¦å¨å æ ¸ï¼èæ¯æä½ ç Linux å æ ¸ççæ¬å·éä½æåé«ï¼æ¥éåº glibcã
ããGcc ççæ¬å·ï¼æ¨èç¨ gcc-2. 以ä¸çã太èççæ¬ç¼è¯å¯è½ä¼åºé®é¢ãGcc-2..3 æ¯ä¸ä¸ªæ¯è¾ç¨³å®ççæ¬ï¼ä¹æ¯å æ ¸å¼å人åæ¨èç¨çä¸ä¸ª gcc çæ¬ã
ããå¦æä½ åç°æ æ³ç¼è¯è¿å»ï¼æå¯è½æ¯ä½ éç¨ç软件ä¸æçå å ¥äºä¸äºæ°çç¹æ§èå ¶ä»æé软件ä¸æ¯æçåå ï¼å°±ç¸åºéä½è¯¥è½¯ä»¶ççæ¬å·ãä¾å¦æå¼å§ç¨ gcc-3.3.2ï¼åç°ç¼è¯ä¸è¿ï¼æ¥ asãld ççæ¬å¤ªèï¼æå°±æ gcc é为 2..3ã 太æ°ççæ¬å¤§å¤æ²¡ç»è¿å¤§éçæµè¯ï¼å»ºè®®ä¸è¦éç¨ã
ããå页é¦
ãã2. 建ç«å·¥ä½ç®å½
ããé¦å ï¼æ们建ç«å 个ç¨æ¥å·¥ä½çç®å½ï¼
ããå¨ä½ çç¨æ·ç®å½ï¼æç¨çæ¯ç¨æ·liangï¼å æ¤ç¨æ·ç®å½ä¸º /home/liangï¼å 建ç«ä¸ä¸ªé¡¹ç®ç®å½embeddedã
ãã$pwd
ãã/home/liang
ãã$mkdir embedded
ããåå¨è¿ä¸ªé¡¹ç®ç®å½ embedded ä¸å»ºç«ä¸ä¸ªç®å½ build-toolsãkernel å toolsã
ããbuild-tools-ç¨æ¥åæ¾ä½ ä¸è½½ç binutilsãgcc å glibc çæºä»£ç åç¨æ¥ç¼è¯è¿äºæºä»£ç çç®å½ã
ããkernel-ç¨æ¥åæ¾ä½ çå æ ¸æºä»£ç åå æ ¸è¡¥ä¸ã
ããtools-ç¨æ¥åæ¾ç¼è¯å¥½ç交åç¼è¯å·¥å ·ååºæ件ã
ãã$cd embedded
ãã$mkdir build-tools kernel tools
ããæ§è¡å®åç®å½ç»æå¦ä¸ï¼
ãã$ls embedded
ããbuild-tools kernel tools
ãã3. è¾åºåç¯å¢åé
ããæ们è¾åºå¦ä¸çç¯å¢åéæ¹ä¾¿æ们ç¼è¯ã
ãã$export PRJROOT=/home/liang/embedded
ãã$export TARGET=arm-linux
ãã$export PREFIX=$PRJROOT/tools
ãã$export TARGET_PREFIX=$PREFIX/$TARGET
ãã$export PATH=$PREFIX/bin:$PATH
ããå¦æä½ ä¸æ¯ç¨ç¯å¢åéçï¼ä½ å¯ä»¥ç´æ¥ç¨ç»å¯¹æç¸å¯¹è·¯å¾ãæå¦æä¸ç¨ç¯å¢åéï¼ä¸è¬é½ç¨ç»å¯¹è·¯å¾ï¼ç¸å¯¹è·¯å¾ææ¶ä¼å¤±è´¥ãç¯å¢åéä¹å¯ä»¥å®ä¹å¨.bashrcæ件ä¸ï¼è¿æ ·å½ä½ logoutææ¢äºæ§å¶å°æ¶ï¼å°±ä¸ç¨èæ¯exportè¿äºåéäºã
ããä½ç³»ç»æåä½ çTAEGETåéç对åºå¦ä¸è¡¨
ããä½ å¯ä»¥å¨éè¿glibcä¸çconfig.subèæ¬æ¥ç¥éï¼ä½ çTARGETåéæ¯å¦è¢«æ¯æï¼ä¾å¦ï¼
ãã$./config.sub arm-linux
ããarm-unknown-linux-gnu
ããå¨æçç¯å¢ä¸ï¼config.sub å¨ glibc-2.2.3/scripts ç®å½ä¸ã
ããç½ä¸è¿æä¸äº HOWTO å¯ä»¥åèï¼ARM ä½ç³»ç»æçãThe源码 GNU Toolchain for ARM Target HOWTOãï¼PowerPC ä½ç³»ç»æçãLinux for PowerPC Embedded Systems HOWTOãçã对TARGETçéåå¯è½æ帮å©ã
ãã4. 建ç«ç¼è¯ç®å½
ãã为äºææºç åç¼è¯æ¶çæçæ件åå¼ï¼ä¸è¬çç¼è¯å·¥ä½ä¸å¨çæºç ç®å½ä¸ï¼è¦å¦å»ºä¸ä¸ªç®å½æ¥ä¸é¨ç¨äºç¼è¯ãç¨ä»¥ä¸çå½ä»¤æ¥å»ºç«ç¼è¯ä½ ä¸è½½çbinutilsãgccåglibcçæºä»£ç çç®å½ã
ãã$cd $PRJROOT/build-tools
ãã$mkdir build-binutils build-boot-gcc build-gcc build-glibc gcc-patch
ããbuild-binutils-ç¼è¯binutilsçç®å½
ããbuild-boot-gcc-ç¼è¯gcc å¯å¨é¨åçç®å½
ããbuild-glibc-ç¼è¯glibcçç®å½
ããbuild-gcc-ç¼è¯gcc å ¨é¨çç®å½
ããgcc-patch-æ¾gccçè¡¥ä¸çç®å½
ããgcc-2..3 çè¡¥ä¸æ gcc-2..3-2.patchãgcc-2..3-no-fixinc.patch ågcc-2..3-returntype-fix.patchï¼å¯ä»¥ä» http://www.linuxfromscratch.org/ ä¸è½½å°è¿äºè¡¥ä¸ã
ããåå°ä½ ä¸è½½ç binutils-2..1ãgcc-2..3ãglibc-2.2.3 å glibc-linuxthreads-2.2.3 çæºä»£ç æ¾å ¥ build-tools ç®å½ä¸
ããçä¸ä¸ä½ ç build-tools ç®å½ï¼æ以ä¸å 容ï¼
ãã$ls
ããbinutils-2..1.tar.bz2 build-gcc gcc-patch
ããbuild-binutls build-glibc glibc-2.2.3.tar.gz
ããbuild-boot-gcc gcc-2..3.tar.gz glibc-linuxthreads-2.2.3.tar.gz
ããå页é¦
ãã建ç«å æ ¸å¤´æ件
ããæä½ ä» www.kernel.org ä¸è½½çå æ ¸æºä»£ç æ¾å ¥ $PRJROOT /kernel ç®å½
ããè¿å ¥ä½ ç kernel ç®å½ï¼
ãã$cd $PRJROOT /kernel
ãã解å¼å æ ¸æºä»£ç
ãã$tar -xzvf linux-2.4..tar.gz
ããæ
ãã$tar -xjvf linux-2.4..tar.bz2
ããå°äº 2.4. çå æ ¸çæ¬è§£å¼ä¼çæä¸ä¸ª linux ç®å½ï¼æ²¡å¸¦çæ¬å·ï¼å°±å°å ¶æ¹åã
ãã$mv linux linux-2.4.x
ããç» Linux å æ ¸æä¸ä½ çè¡¥ä¸
ãã$cd linux-2.4.
ãã$patch -p1 < ../patch-2.4.-rmk2
ããç¼è¯å æ ¸çæ头æ件
ãã$make ARCH=arm CROSS_COMPILE=arm-linux- menuconfig
ããä½ ä¹å¯ä»¥ç¨ config å xconfig æ¥ä»£æ¿ menuconfigï¼ä½è¿æ ·ç¨å¯è½ä¼æ²¡æ设置æäºé ç½®æ件é项å没æçæä¸é¢ç¼è¯æéç头æ件ãæ¨èå¤§å®¶ç¨ make menuconfigï¼è¿ä¹æ¯å æ ¸å¼å人åç¨çæå¤çé ç½®æ¹æ³ãé ç½®å®éåºå¹¶ä¿åï¼æ£æ¥ä¸ä¸çå æ ¸ç®å½ä¸ç include/linux/version.h å include/linux/autoconf.h æ件æ¯ä¸æ¯çæäºï¼è¿æ¯ç¼è¯ glibc æ¯è¦ç¨å°çï¼version.h å autoconf.h æ件çåå¨ï¼ä¹è¯´æäºä½ çæäºæ£ç¡®ç头æ件ã
ããè¿è¦å»ºç«å 个æ£ç¡®çé¾æ¥
ãã$cd include
ãã$ln -s asm-arm asm
ãã$cd asm
ãã$ln -s arch-epxa arch
ãã$ln -s proc-armv proc
ããæ¥ä¸æ¥ä¸ºä½ ç交åç¼è¯ç¯å¢å»ºç«ä½ çå æ ¸å¤´æ件çé¾æ¥
ãã$mkdir -p $TARGET_PREFIX/include
ãã$ln -s $PRJROOT/kernel/linux-2.4./include/linux $TARGET_PREFIX/include/linux
ãã$in -s $PRJROOT/kernel/linux-2.4./include/asm-arm $TARGET_PREFIX/include/asm
ããä¹å¯ä»¥æ Linux å æ ¸å¤´æ件æ·è´è¿æ¥ç¨
ãã$mkdir -p $TARGET_PREFIX/include
ãã$cp -r $PRJROOT/kernel/linux-2.4./include/linux $TARGET_PREFIX/include
ãã$cp -r $PRJROOT/kernel/linux-2.4./include/asm-arm $TARGET_PREFIX/include
ããå页é¦
ãã建ç«äºè¿å¶å·¥å ·ï¼binutilsï¼
ããbinutilsæ¯ä¸äºäºè¿å¶å·¥å ·çéåï¼å ¶ä¸å å«äºæ们常ç¨å°çasåldã
ããé¦å ï¼æ们解åæ们ä¸è½½çbinutilsæºæ件ã
ãã$cd $PRJROOT/build-tools
ãã$tar -xvjf binutils-2..1.tar.bz2
ããç¶åè¿å ¥build-binutilsç®å½é ç½®åç¼è¯binutilsã
ãã$cd build-binutils
ãã$../binutils-2..1/configure --target=$TARGET --prefix=$PREFIX
ãã--target é项æ¯æåºæ们çæçæ¯ arm-linux çå·¥å ·ï¼--prefix æ¯æåºæ们å¯æ§è¡æ件å®è£ çä½ç½®ã
ããä¼åºç°å¾å¤ checkï¼æå产ç Makefile æ件ã
ããæäº Makefile åï¼æ们æ¥ç¼è¯å¹¶å®è£ binutilsï¼å½ä»¤å¾ç®åã
ãã$make
ãã$make install
ããçä¸ä¸æ们 $PREFIX/bin ä¸ççæçæ件
ãã$ls $PREFIX/bin
ããarm-linux-addr2line arm-linux-gasp arm-linux-objdump arm-linux-strings
ããarm-linux-ar arm-linux-ld arm-linux-ranlib arm-linux-strip
ããarm-linux-as arm-linux-nm arm-linux-readelf
ããarm-linux-c++filt arm-linux-objcopy arm-linux-size
ããæ们æ¥è§£éä¸ä¸ä¸é¢çæçå¯æ§è¡æ件é½æ¯ç¨æ¥å¹²ä»ä¹ç
ããadd2line - å°ä½ è¦æ¾çå°å转ææ件åè¡å·ï¼å®è¦ä½¿ç¨ debug ä¿¡æ¯ã
ããAr-产çãä¿®æ¹å解å¼ä¸ä¸ªåæ¡£æ件
ããAs-gnu çæ±ç¼å¨
ããC++filt-C++ å java ä¸æä¸ç§éè½½å½æ°ï¼æç¨çéè½½å½æ°æåä¼è¢«ç¼è¯è½¬åææ±ç¼çæ å·ï¼c++filt å°±æ¯å®ç°è¿ç§ååç转åï¼æ ¹æ®æ å·å¾å°å½æ°åã
ããGasp-gnu æ±ç¼å¨é¢ç¼è¯å¨ã
ããLd-gnu çè¿æ¥å¨
ããNm-ååºç®æ æ件ç符å·å对åºçå°å
ããObjcopy-å°æç§æ ¼å¼çç®æ æ件转åæå¦å¤æ ¼å¼çç®æ æ件
ããObjdump-æ¾ç¤ºç®æ æ件çä¿¡æ¯
ããRanlib-为ä¸ä¸ªåæ¡£æ件产çä¸ä¸ªç´¢å¼ï¼å¹¶å°è¿ä¸ªç´¢å¼åå ¥åæ¡£æ件ä¸
ããReadelf-æ¾ç¤º elf æ ¼å¼çç®æ æ件çä¿¡æ¯
ããSize-æ¾ç¤ºç®æ æ件å个èç大å°åç®æ æ件ç大å°
ããStrings-æå°åºç®æ æ件ä¸å¯ä»¥æå°çå符串ï¼æ个é»è®¤çé¿åº¦ï¼ä¸º4
ããStrip-å¥æç®æ æ件çææç符å·ä¿¡æ¯
ããå页é¦
ãã建ç«åå§ç¼è¯å¨ï¼bootstrap gccï¼
ããé¦å è¿å ¥ build-tools ç®å½ï¼å°ä¸è½½ gcc æºä»£ç 解å
ãã$cd $PRJROOT/build-tools
ãã$tar -xvzf gcc-2..3.tar.gz
ããç¶åè¿å ¥ gcc-2..3 ç®å½ç» gcc æä¸è¡¥ä¸
ãã$cd gcc-2..3
ãã$patch -p1< ../gcc-patch/gcc-2..3.-2.patch
ãã$patch -p1< ../gcc-patch/gcc-2..3.-no-fixinc.patch
ãã$patch -p1< ../gcc-patch/gcc-2..3-returntype-fix.patch
ããecho timestamp > gcc/cstamp-h.in
ããå¨æ们ç¼è¯å¹¶å®è£ gcc åï¼æ们å è¦æ¹ä¸ä¸ªæ件 $PRJROOT/gcc/config/arm/t-linuxï¼æ
ããTARGET_LIBGCC2-CFLAGS = -fomit-frame-pointer -fPIC
ããè¿ä¸è¡æ¹ä¸º
ããTARGET_LIBGCC2-CFLAGS = -fomit-frame-pointer -fPIC -Dinhibit_libc -D__gthr_posix_h
ããä½ å¦æ没å®ä¹ -Dinhibitï¼ç¼è¯æ¶å°ä¼æ¥å¦ä¸çé误
ãã../../gcc-2..3/gcc/libgcc2.c:: stdlib.h: No such file or directory
ãã../../gcc-2..3/gcc/libgcc2.c:: unistd.h: No such file or directory
ããmake[3]: *** [libgcc2.a] Error 1
ããmake[2]: *** [stmp-multilib-sub] Error 2
ããmake[1]: *** [stmp-multilib] Error 1
ããmake: *** [all-gcc] Error 2
ããå¦æ没æå®ä¹ -D__gthr_posix_hï¼ç¼è¯æ¶ä¼æ¥å¦ä¸çé误
ããIn file included from gthr-default.h:1,
ããfrom ../../gcc-2..3/gcc/gthr.h:,
ããfrom ../../gcc-2..3/gcc/libgcc2.c::
ãã../../gcc-2..3/gcc/gthr-posix.h:: pthread.h: No such file or directory
ããmake[3]: *** [libgcc2.a] Error 1
ããmake[2]: *** [stmp-multilib-sub] Error 2
ããmake[1]: *** [stmp-multilib] Error 1
ããmake: *** [all-gcc] Error 2
ããè¿æä¸ç§ä¸-Dinhibitåçææçæ¹æ³ï¼é£å°±æ¯å¨ä½ é ç½®configureæ¶å¤å ä¸ä¸ªåæ°-with-newlibï¼è¿ä¸ªé项ä¸ä¼è¿«ä½¿æä»¬å¿ é¡»ä½¿ç¨newlibãæ们ç¼è¯äºbootstrap-gccåï¼ä»ç¶å¯ä»¥éæ©ä»»ä½cåºã
ããæ¥çå°±æ¯é ç½®boostrap gccï¼ åé¢è¦ç¨bootstrap gcc æ¥ç¼è¯ glibc åºã
ãã$cd ..; cd build-boot-gcc
ãã$../gcc-2..3/configure --target=$TARGET --prefix=$PREFIX \
ãã>--without-headers --enable-languages=c --disable-threads
ããè¿æ¡å½ä»¤ä¸ç -targetã--prefix åé ç½® binutils çå«ä¹æ¯ç¸åçï¼--without-headers å°±æ¯æä¸éè¦å¤´æ件ï¼å 为æ¯äº¤åç¼è¯å·¥å ·ï¼ä¸éè¦æ¬æºä¸ç头æ件ã-enable-languages=cæ¯ææ们ç boot-gcc åªæ¯æ c è¯è¨ã--disable-threads æ¯å»æ thread åè½ï¼è¿ä¸ªåè½éè¦ glibc çæ¯æã
ããæ¥çæ们ç¼è¯å¹¶å®è£ boot-gcc
ãã$make all-gcc
ãã$make install-gcc
ããæ们æ¥çç $PREFIX/bin éé¢å¤äºåªäºä¸è¥¿
ãã$ls $PREFIX/bin
ããä½ ä¼åç°å¤äº arm-linux-gcc ãarm-linux-unprotoizeãcpp å gcov å 个æ件ã
ããGcc-gnu ç C è¯è¨ç¼è¯å¨
ããUnprotoize-å° ANSI C çæºç 转å为 K&R C çå½¢å¼ï¼å»æå½æ°ååä¸çåæ°ç±»åã
ããCpp-gnuç C çé¢ç¼è¯å¨
ããGcov-gcc çè¾ å©æµè¯å·¥å ·ï¼å¯ä»¥ç¨å®æ¥åæåä¼ç¨åºã
ããä½¿ç¨ gcc3.2 以å gcc3.2 以ä¸çæ¬æ¶ï¼é ç½® boot-gcc ä¸è½ä½¿ç¨ --without-headers é项ï¼èéè¦ä½¿ç¨ glibc ç头æ件ã
ããå页é¦
ããå»ºç« c åº(glibc)
ããé¦å 解å glibc-2.2.3.tar.gz å glibc-linuxthreads-2.2.3.tar.gz æºä»£ç
ãã$cd $PRJROOT/build-tools
ãã$tar -xvzf glibc-2.2.3.tar.gz
ãã$tar -xzvf glibc-linuxthreads-2.2.3.tar.gz --directory=glibc-2.2.3
ããç¶åè¿å ¥ build-glibc ç®å½é ç½® glibc
ãã$cd build-glibc
ãã$CC=arm-linux-gcc ../glibc-2.2.3/configure --host=$TARGET --prefix="/usr"
ãã--enable-add-ons --with-headers=$TARGET_PREFIX/include
ããCC=arm-linux-gcc æ¯æ CC åé设æä½ åç¼è¯å®çboostrap gccï¼ç¨å®æ¥ç¼è¯ä½ çglibcã--enable-add-onsæ¯åè¯glibcç¨ linuxthreads å ï¼å¨ä¸é¢æ们已ç»å°å®æ¾å ¥äº glibc æºç ç®å½ä¸ï¼è¿ä¸ªé项çä»·äº -enable-add-ons=linuxthreadsã--with-headers åè¯ glibc æ们çlinux å æ ¸å¤´æ件çç®å½ä½ç½®ã
ããé ç½®å®åå°±å¯ä»¥ç¼è¯åå®è£ glibc
ãã$make
ãã$make install_root=$TARGET_PREFIX prefix="" install
ããç¶åä½ è¿è¦ä¿®æ¹ libc.so æ件
ããå°
ããGROUP ( /lib/libc.so.6 /lib/libc_nonshared.a)
ããæ¹ä¸º
ããGROUP ( libc.so.6 libc_nonshared.a)
ããè¿æ ·è¿æ¥ç¨åº ld å°±ä¼å¨ libc.so æå¨çç®å½æ¥æ¾å®éè¦çåºï¼å ä¸ºä½ çæºåç/libç®å½å¯è½å·²ç»è£ äºä¸ä¸ªç¸åååçåºï¼ä¸ä¸ªä¸ºç¼è¯å¯ä»¥å¨ä½ ç宿主æºä¸è¿è¡çç¨åºçåºï¼èä¸æ¯ç¨äºäº¤åç¼è¯çã
ããå页é¦
ãã建ç«å ¨å¥ç¼è¯å¨ï¼full gccï¼
ããå¨å»ºç«boot-gcc çæ¶åï¼æ们åªæ¯æäºCãå°è¿éï¼æ们就è¦å»ºç«å ¨å¥ç¼è¯å¨ï¼æ¥æ¯æCåC++ã
ãã$cd $PRJROOT/build-tools/build-gcc
ãã$../gcc-2..3/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++
ãã--enable-languages=c,c++ åè¯ full gcc æ¯æ c å c++ è¯è¨ã
ããç¶åç¼è¯åå®è£ ä½ ç full gcc
ãã$make all
ãã$make install
ããæ们åæ¥çç $PREFIX/bin éé¢å¤äºåªäºä¸è¥¿
ãã$ls $PREFIX/bin
ããä½ ä¼åç°å¤äº arm-linux-g++ ãarm-linux-protoize å arm-linux-c++ å 个æ件ã
ããG++-gnuç c++ ç¼è¯å¨ã
ããProtoize-ä¸Unprotoizeç¸åï¼å°K&R Cçæºç 转å为ANSI Cçå½¢å¼ï¼å½æ°ååä¸å å ¥åæ°ç±»åã
ããC++-gnu ç c++ ç¼è¯å¨ã
ããå°è¿éä½ ç交åç¼è¯å·¥å ·å°±ç®åå®äºï¼ç®åéªè¯ä¸ä¸ä½ ç交åç¼è¯å·¥å ·ã
ããç¨å®æ¥ç¼è¯ä¸ä¸ªå¾ç®åçç¨åº helloworld.c
ãã#include <stdio.h>
ããint main(void)
ãã{
ããprintf("hello world\n");
ããreturn 0;
ãã}
ãã$arm-linux-gcc helloworld.c -o helloworld
ãã$file helloworld
ããhelloworld: ELF -bit LSB executable, ARM, version 1,
ããdynamically linked (uses shared libs), not stripped
ããä¸é¢çè¾åºè¯´æä½ ç¼è¯äºä¸ä¸ªè½å¨ arm ä½ç³»ç»æä¸è¿è¡ç helloworldï¼è¯æä½ çç¼è¯å·¥å ·åæåäºã
è½¬è½½ä» ä¾åèï¼çæå±äºåä½è
GCC编译工具链(更新中)
GCC编译工具链是围绕GCC编译器构建的一套开发工具,用于将源代码转化为可执行程序,源码主要包括GCC编译器、源码Binutils工具集和glibc库。源码poco库源码分析GCC作为一款强大的源码多语言编译器,最初支持C语言,源码后来扩展到C++、源码Fortran和Java等,源码其性能优秀,源码效率比一般编译器高%~%。源码官方网站:gcc.gnu.org。源码qi无线充源码
Ubuntu系统内置了GCC编译器,源码可通过命令查看版本和路径。源码Binutils是源码GNU二进制工具集,与GCC一起安装,源码常用工具如readelf。台式白发魔女源码glibc是C语言的标准库,对程序运行至关重要,如read、write等函数,Ubuntu系统中的北大树洞源码glibc版本可通过命令查看,学习时可研究其源代码,官网地址为The GNU C Library。
要安装ARM-GCC,有三种方式,包括使用APT安装、html文件管理源码第三方Linaro工具链或直接编译。交叉编译是指在一种架构的系统上为另一种架构生成代码,例如,使用arm-linux-gnueabihf-gcc编译Hello World程序。交叉编译的流程与本地编译相似,主要区别在于编译工具,生成的可执行文件适用于特定的ARM平台,如使用readelf工具分析其结构。
在编译过程中,创建一个名为helloworld.c的文件,编写代码并执行交叉编译命令,最终生成的helloworld是ARM平台的可执行文件。readelf工具随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ä¸ç交åç¼è¯ç¯å¢è®¾ç½®
éç¨äº¤åç¼è¯ç主è¦åå å¨äºï¼å¤æ°åµå ¥å¼ç®æ ç³»ç»ä¸è½æä¾è¶³å¤çèµæºä¾ç¼è¯è¿ç¨ä½¿ç¨ï¼å èåªå¥½å°ç¼è¯å·¥ç¨è½¬ç§»å°é«æ§è½ç主æºä¸è¿è¡ã
linuxä¸ç交åç¼è¯ç¯å¢éè¦å æ¬ä»¥ä¸å 个é¨åï¼
1.对ç®æ ç³»ç»çç¼è¯å¨gcc
2.对ç®æ ç³»ç»çäºè¿å¶å·¥å ·binutils
3.ç®æ ç³»ç»çæ åcåºglibc
4.ç®æ ç³»ç»çlinuxå æ ¸å¤´æ件
交åç¼è¯ç¯å¢ç建ç«æ¥éª¤
ä¸ãä¸è½½æºä»£ç ä¸è½½å æ¬binutilsãgccãglibcålinuxå æ ¸çæºä»£ç ï¼éè¦æ³¨æçæ¯ï¼glibcåå æ ¸æºä»£ç ççæ¬å¿ é¡»ä¸ç®æ æºä¸å®é 使ç¨ççæ¬ä¿æä¸è´ï¼ï¼å¹¶è®¾å®shellåéPREFIXæå®å¯æ§è¡ç¨åºçå®è£ è·¯å¾ã
äºãç¼è¯binutils é¦å è¿è¡configureæ件ï¼å¹¶ä½¿ç¨--prefix=$PREFIXåæ°æå®å®è£ è·¯å¾ï¼ä½¿ç¨--target=arm-linuxåæ°æå®ç®æ æºç±»åï¼ç¶åæ§è¡make installã
ä¸ãé ç½®linuxå æ ¸å¤´æ件
é¦å æ§è¡make mrproperè¿è¡æ¸ çå·¥ä½ï¼ç¶åæ§è¡make config ARCH=armï¼æmake menuconfig/xconfig ARCH=armï¼è¿è¡é ç½®ï¼æ³¨æï¼ä¸å®è¦å¨å½ä»¤è¡ä¸ä½¿ç¨ARCH=armæå®cpuæ¶æï¼å 为缺çæ¶æ为主æºçcpuæ¶æï¼ï¼è¿ä¸æ¥éè¦æ ¹æ®ç®æ æºçå®é æ åµè¿è¡è¯¦ç»çé ç½®ï¼ç¬è è¿è¡çå®éªä¸ç®æ æºä¸ºHPçipaq-hp PDAï¼å è设置system type为SAX0ï¼SAX0 Implementationsä¸éæ©Compaq iPAQ H/Hã
é ç½®å®æä¹åï¼éè¦å°å æ ¸å¤´æ件æ·è´å°å®è£ ç®å½ï¼ cp -dR include/asm-arm $PREFIX/arm-linux/include/asm cp -dR include/linux $PREFIX/arm-linux/include/linux
åã第ä¸æ¬¡ç¼è¯gcc
é¦å è¿è¡configureæ件ï¼ä½¿ç¨--prefix=$PREFIXåæ°æå®å®è£ è·¯å¾ï¼ä½¿ç¨--target=arm-linuxåæ°æå®ç®æ æºç±»åï¼å¹¶ä½¿ç¨--disable-threadsã--disable-sharedã--enable-languages=cåæ°ï¼ç¶åæ§è¡make installãè¿ä¸æ¥å°çæä¸ä¸ªæç®çgccãç±äºç¼è¯æ´ä¸ªgccæ¯éè¦ç®æ æºçglibcåºçï¼å®ç°å¨è¿ä¸åå¨ï¼å æ¤éè¦é¦å çæä¸ä¸ªæç®çgccï¼å®åªéè¦å ·å¤ç¼è¯ç®æ æºglibcåºçè½åå³å¯ã
äºã交åç¼è¯glibc
è¿ä¸æ¥éª¤çæç代ç æ¯é对ç®æ æºcpuçï¼å æ¤å®å±äºä¸ä¸ªäº¤åç¼è¯è¿ç¨ã该è¿ç¨è¦ç¨å°linuxå æ ¸å¤´æ件ï¼é»è®¤è·¯å¾ä¸º$PREFIX/arm-linux/sys-linuxï¼å èéè¦å¨$PREFIX/arm-linuxä¸å»ºç«ä¸ä¸ªå为sys-linuxç软è¿æ¥ï¼ä½¿å ¶å æ ¸å¤´æ件æå¨çincludeç®å½ï¼æè ï¼ä¹å¯ä»¥å¨æ¥ä¸æ¥è¦æ§è¡çconfigureå½ä»¤ä¸ä½¿ç¨--with-headersåæ°æå®linuxå æ ¸å¤´æ件çå®é è·¯å¾ã
configureçè¿è¡åæ°è®¾ç½®å¦ä¸ï¼å 为æ¯äº¤åç¼è¯ï¼æ以è¦å°ç¼è¯å¨åéCC设为arm-linux-gccï¼ï¼ CC=arm-linux-gcc ./configure --prefix=$PREFIX/arm-linux --host=arm-linux --enable-add-ons æåï¼æ以ä¸é ç½®æ§è¡configureåmake installï¼glibcç交åç¼è¯è¿ç¨å°±ç®å®æäºï¼è¿ééè¦æåºçæ¯ï¼glibcçå®è£ è·¯å¾è®¾ç½®ä¸º$PREFIXARCH=arm/arm-linuxï¼å¦ææ¤å¤è®¾ç½®ä¸å½ï¼ç¬¬äºæ¬¡ç¼è¯gccæ¶å¯è½æ¾ä¸å°glibcç头æ件ååºã
å ã第äºæ¬¡ç¼è¯gcc
è¿è¡configureï¼åæ°è®¾ç½®ä¸º--prefix=$PREFIX --target=arm-linux --enable-languages=c,c++ã
è¿è¡make installã
å°æ¤ä¸ºæ¢æ´ä¸ªäº¤åç¼è¯ç¯å¢å°±å®å ¨çæäºã
å ç¹æ³¨æäºé¡¹
第ä¸ç¹ãå¨ç¬¬ä¸æ¬¡ç¼è¯gccçæ¶åå¯è½ä¼åºç°æ¾ä¸å°stdio.hçé误ï¼è§£å³åæ³æ¯ä¿®æ¹gcc/config/arm/t-linuxæ件ï¼å¨TARGET_LIBGCC2_CFLAGSåéç设å®ä¸å¢å -Dinhibit_libcå-D__gthr_posix_hã