1.编译TVM遇到 collect2: fatal error: cannot find 'ld'
2.å¦ä½å¶ä½arm-linux-gccç¼è¯å·¥å
·
3.ubuntuå¹³å°å¦ä½ä½¿ç¨å½ä»¤ä¸è½½è½¯ä»¶
4.å¦ä½ä¸ºåµå
¥å¼å¼å建ç«äº¤åç¼è¯ç¯å¢
编译TVM遇到 collect2: fatal error: cannot find 'ld'
在尝试编译TVM源码时,源码我在Ubuntu.上遇到了一个错误,安装具体是源码"collect2: fatal error: cannot find 'ld'"。这让我感到困惑,安装hatmap源码因为我已经确认ld已经被安装。源码
通过google搜索,安装软件源码安全管理我检查了ld的源码安装路径,发现它确实存在。安装我尝试了重新安装binutils,源码使用命令"sudo apt install --reinstall binutils",安装但问题仍然没有解决。源码
我重新思考问题,安装发现cmake编译时使用的源码资源教程下载源码链接器是lld,而不是安装官方推荐的ld。这可能是源码问题的关键。为了解决这个问题,商城源码 易支付我安装了lld(使用命令"apt-get install lld"),然后重新编译,这次成功了。在线受理业务源码
TVM建议使用llvm进行编译,因此链接器使用的是lld。这次的经验让我意识到,确认链接器版本和正确配置cmake参数对于编译过程至关重要。通过这个过程,我学到了如何在遇到编译问题时,系统地排查并解决问题。
å¦ä½å¶ä½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
ubuntuå¹³å°å¦ä½ä½¿ç¨å½ä»¤ä¸è½½è½¯ä»¶
1. 使ç¨apt-get installæ¥å®è£ åºç¨ç¨åºæ¯æ常è§çä¸ç§å®è£ æ¹æ³ï¼æ¯å¦è¦å®è£ buildessentialè¿ä¸ªè½¯ä»¶ï¼ä½¿ç¨ä»¥ä¸ï¼ä»ä¼å¸®ææææçä¾èµå é½ä¸èµ·å®è£ äºã
sudo apt-get install build-essential
æ§è¡ä¸è¿°å½ä»¤ä»¥åï¼æ们å¯ä»¥çå°ä¸ä¸ä¿¡æ¯ï¼
The following extra packages will be installed:表示ææéè¦åå®è£ çä¾èµå ã
sudo apt-get install build-essential
[sudo] password for enadmin:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
binutils cpp cpp-4.6 dpkg-dev fakeroot g++ g++-4.6 gcc gcc-4.6
libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
libc-bin libc-dev-bin libc6 libc6-dev libdpkg-perl libgomp1 libmpc2 libmpfr4
libquadmath0 libstdc++6-4.6-dev linux-libc-dev manpages-dev
Suggested packages:
binutils-doc cpp-doc gcc-4.6-locales debian-keyring g++-multilib
g++-4.6-multilib gcc-4.6-doc libstdc++6-4.6-dbg gcc-multilib autoconf
automake1.9 libtool flex bison gdb gcc-doc gcc-4.6-multilib
libmudflap0-4.6-dev libgcc1-dbg libgomp1-dbg libquadmath0-dbg
libmudflap0-dbg binutils-gold glibc-doc libstdc++6-4.6-doc
The following NEW packages will be installed:
binutils build-essential cpp cpp-4.6 dpkg-dev fakeroot g++ g++-4.6 gcc
gcc-4.6 libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libc-dev-bin libc6-dev libdpkg-perl libgomp1 libmpc2
libmpfr4 libquadmath0 libstdc++6-4.6-dev linux-libc-dev manpages-dev
The following packages will be upgraded:
libc-bin libc6
2 upgraded, newly installed, 0 to remove and not upgraded.
Need to get .3 MB of archives.
After this operation, .6 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
ä¸é¢ç»åºapt-getççåç§åæ°ï¼
apt-get install xxx å®è£ xxx ãå¦æ带æåæ°ï¼é£ä¹-d è¡¨ç¤ºä» ä¸è½½ ï¼-f 表示强å¶å®è£
apt-get remove xxx å¸è½½xxx
apt-get update æ´æ°è½¯ä»¶ä¿¡æ¯æ°æ®åº
apt-get upgrade è¿è¡ç³»ç»å级
apt-cache search æ索软件å
Tipsï¼å»ºè®®æ¨ç»å¸¸ä½¿ç¨âapt-get updateâå½ä»¤æ¥æ´æ°æ¨ç软件信æ¯æ°æ®åº ã
apt-getç论ä¸æ¯è¦æ±è½å¤èç½ï¼ä½æ¯å¦æå¶ä½äºæ¬å°æºï¼å°±ä¸éè¦èç½ï¼å¶ä½æ¬å°æºå¯ä»¥åèï¼ubuntuå¶ä½æ¬å°æºã
2. dpkgå®è£ debå
Ubuntu软件å æ ¼å¼ä¸ºdebï¼å®è£ æ¹æ³å¦ä¸ï¼
sudo dpkg -i package.deb
dpkgç详ç»ä½¿ç¨æ¹æ³ï¼ç½ä¸æå¾å¤ï¼ä¸é¢ç®ååäºå 个ï¼
dpkg -i package.deb å®è£ å
dpkg -r package å é¤å
dpkg -P package å é¤å ï¼å æ¬é ç½®æ件ï¼
dpkg -L package ååºä¸è¯¥å å ³èçæ件
dpkg -l package æ¾ç¤ºè¯¥å ççæ¬
dpkg âunpack package.deb è§£å¼ deb å çå 容
dpkg -S keyword æç´¢æå±çå å 容
dpkg -l ååºå½åå·²å®è£ çå
dpkg -c package.deb ååº deb å çå 容
dpkg âconfigure package é ç½®å
æ ¹æ®Ubuntuä¸æ论åä¸ä»ç»ï¼ä½¿ç¨apt-getæ¹æ³å®è£ ç软件ï¼ææä¸è½½çdebå é½ç¼åå°äº/var/cache/apt/archivesç®å½ä¸äºï¼æ以å¯ä»¥æ常ç¨çdebå å¤ä»½åºæ¥ï¼çè³åæISOå·¥å ·å ãå»çï¼ä»¥åå®è£ Ubuntuæ¶å°±å¯ä»¥å¨æ²¡æç½ç»ç¯å¢çæ åµä¸è¿è¡äºãä¸é¢çå½ä»¤æ¯æ·è´archivesè¿ä¸ªç®å½å°/var/cache/apt/ç®å½ä¸ï¼æ¿æ¢åæçarchives
enadmin@ubuntu-server:~/ftp$ sudo cp -r archives/ /var/cache/apt/
3. make installæºä»£ç å®è£ ã
å¦æè¦ä½¿ç¨makeå®è£ çè¯ï¼é£ä¹å¿ é¡»å¾å®è£ build-essentialè¿ä¸ªä¾èµå ï¼å®è£ æ¹æ³å·²ç»å¨åé¢è¯´è¿äºãå¨å®è£ å®æ¯ä»¥åï¼æ们就å¯ä»¥è¿è¡æºç å®è£ ãæºç å®è£ 大è´å¯ä»¥å为ä¸æ¥éª¤ï¼ï¼./configureï¼âï¼ ç¼è¯ï¼sudo makeï¼ âï¼ å®è£ ï¼sudo make installï¼ã
é ç½®ï¼è¿æ¯ç¼è¯æºä»£ç ç第ä¸æ¥ï¼éè¿ ./configure å½ä»¤å®æãæ§è¡æ¤æ¥ä»¥ä¾¿ä¸ºç¼è¯æºä»£ç ä½åå¤ã常ç¨çé项æ --prefix=PREFIXï¼ç¨ä»¥æå®ç¨åºçå®è£ ä½ç½®ãæ´å¤çé项å¯éè¿ --help æ¥è¯¢ãä¹ææäºç¨åºæ éæ§è¡æ¤æ¥ã
ç¼è¯ï¼ä¸æ¦é ç½®éè¿ï¼å¯å³å»ä½¿ç¨ make æ令æ¥æ§è¡æºä»£ç çç¼è¯è¿ç¨ãè§è½¯ä»¶çå ·ä½æ åµèå®ï¼ç¼è¯æéçæ¶é´ä¹åæå·®å¼ï¼æ们æè¦åçå°±æ¯èå¿çååéè§å ¶åãæ¤æ¥è½ç¶ä» ä¸ç®åçæ令ï¼ä½ææ¶åæéå°çé®é¢å´ååå¤æãè¾å¸¸ç¢°å°çæ å½¢æ¯ç¨åºç¼è¯å°ä¸éå´æ æ³å满ç»æãæ¤æ¶ï¼éè¦æ ¹æ®åºéæ示åæ以便æ¾å°åºå¯¹ä¹çã
å®è£ ï¼å¦æç¼è¯æ²¡æé®é¢ï¼é£ä¹æ§è¡ sudo make install å°±å¯ä»¥å°ç¨åºå®è£ å°ç³»ç»ä¸äºã
ä¸é¢ä»¥å®è£ nagios为ä¾è¿è¡è¯´æã
//1.解å缩
tar -zxf nagios-4.0.2.tar.gz
//2.è¿å ¥ç®å½
cd nagios-4.0.2
//3.é ç½®
./configure --prefix=/usr/local/nagios
//4.ç¼è¯
make all
//5.å®è£
make install && make install-init && make install-commandmode && make install-config
以ä¸å°±æ¯æºä»£ç å®è£ æ¹å¼ã
å¦ä½ä¸ºåµå ¥å¼å¼å建ç«äº¤åç¼è¯ç¯å¢
ããä¸é¢æ们å°ä»¥å»ºç«é对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ï¼è¯æä½ çç¼è¯å·¥å ·åæåäºã
è½¬è½½ä» ä¾åèï¼çæå±äºåä½è