CROSSTOOL-NG建立交叉編譯工具鏈
因為考試和學習的原因我已經一段時間沒有玩我的JZ2440,現在終於考完試了,我再次找出了我的JZ2440。我之前學習的時候使用的是韋東山老師提供的開發工具,並沒有自己建立過交叉編譯工具鏈。而這次我就自己動手建立一個交叉編譯的工具鏈
- 平台:UBUNTU 15.04 64位 + crosstool-ng 1.22.0
- 目標平台:ARMv4t, arm9tdmi,s3c2440
1.下載安裝
ubuntu默認沒安裝git
sudo apt-get install git
sudo apt-get install gperf bison flex texinfo gawk libtool libncurses5-dev autoconf
git clone git://crosstool-ng.org/crosstool-ng
cd crosstool-ng
./bootstrap #這里一般會出現錯誤,根據錯誤使用apt-get安裝相應的依賴就可以了
./configure #同上
make
sudo make install
ct-ng #測試是否安裝成功
2.配置自己的交叉編譯環境
將crosstool-ng源碼包中samples/arm-unknown-linux-gnueabi/下的crosstool.config拷貝到源碼包主目錄下,在源碼包主目錄下執行
cp samples/arm-unknown-linux-gnueabi/crosstool.config .config
ct-ng menuconfig #進入配置菜單
Paths and misc options --->
......
(${HOME}/src) Local tarballs directory # 指定制作編譯器所需要的源碼包的下載存放,可以修改成任意位置,請注意權限。現在指定到~/src下。
......
(${HOME}/x-tools/${CT_TARGET}) Prefix directory # 制作好的編譯器所放置的目錄
Target options --->
Target Architecture (arm) ---> # ARM平台
......
Floating point: (software) ---> #很多ARM架構CPU來說是不支持硬浮點運算的,所以選擇軟件方式有更好的兼容性
......
[*] Use EABI # 是否實用EABI方式,對某些指令采用異常的方式來處理(如除法指令),建議選中
Toolchain options --->
.....
(zzm) Tuple's vendor string # 這里可以修改成你自己的個性化名稱,最后會生成arm-yourname-linux-gnueabi這樣的編譯器前綴
Operating System ---> Target OS (linux) #目標操作系統linux
ct-ng build #開始編譯
漫長的編譯,先睡一覺---
3.安裝交叉編譯器
cd ~/x-tools/arm-zzm-linux-gnueabi/bin
./arm-zzm-linux-gnueabi-gcc -v
輸出類似
Using built-in specs.
COLLECT_GCC=./arm-zzm-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/home/zzm/x-tools/arm-zzm-linux-gnueabi/libexec/gcc/arm-zzm-linux-gnueabi/5.3.0/lto-wrapper
Target: arm-zzm-linux-gnueabi
Configured with: /home/zzm/crosstool-ng/.build/src/gcc-5.3.0/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=arm-zzm-linux-gnueabi --prefix=/home/zzm/x-tools/arm-zzm-linux-gnueabi --with-sysroot=/home/zzm/x-tools/arm-zzm-linux-gnueabi/arm-zzm-linux-gnueabi/sysroot --enable-languages=c,c++ --with-float=soft --with-pkgversion='crosstool-NG crosstool-ng-1.22.0-66-g99cf467' --disable-sjlj-exceptions --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --with-gmp=/home/zzm/crosstool-ng/.build/arm-zzm-linux-gnueabi/buildtools --with-mpfr=/home/zzm/crosstool-ng/.build/arm-zzm-linux-gnueabi/buildtools --with-mpc=/home/zzm/crosstool-ng/.build/arm-zzm-linux-gnueabi/buildtools --with-isl=/home/zzm/crosstool-ng/.build/arm-zzm-linux-gnueabi/buildtools --with-libelf=/home/zzm/crosstool-ng/.build/arm-zzm-linux-gnueabi/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --enable-plugin --enable-gold --disable-nls --disable-multilib --with-local-prefix=/home/zzm/x-tools/arm-zzm-linux-gnueabi/arm-zzm-linux-gnueabi/sysroot --enable-long-long
Thread model: posix
gcc version 5.3.0 (crosstool-NG crosstool-ng-1.22.0-66-g99cf467)
這樣就表明我們的交叉編譯器,制作成功了。
把交叉編譯器所在的目錄添加到系統PATH變量中,修改~/.bashrc文件,在其中添加:
export PATH=$PATH:~/x-tools/arm-zzm-linux-gnueabi/bin
執行一下~/.bashrc文件
source ~/.bashrc
這樣我們就可以直接使用arm-zzm-linux-gnueabi-gcc命令了
4.標准化安裝交叉編譯器
由於標准Makefile需要實用標准的交叉編譯器的名稱,一般這個名稱是arm-linux-gcc這樣的。
cd ~/x-tools/arm-zzm-linux-gnueabi/bin
vim link.sh
寫入
#!/bin/sh
PREFIX=arm-zzm-linux-gnueabi- #zzm修改成你設置的
AFTFIX=arm-linux-
ln -s ${PREFIX}gcc ${AFTFIX}gcc
ln -s ${PREFIX}addr2line ${AFTFIX}addr2line
ln -s ${PREFIX}gdbtui ${AFTFIX}gdbtui
ln -s ${PREFIX}ar ${AFTFIX}ar
ln -s ${PREFIX}as ${AFTFIX}as
ln -s ${PREFIX}c++ ${AFTFIX}c++
ln -s ${PREFIX}c++filt ${AFTFIX}c++filt
ln -s ${PREFIX}cpp ${AFTFIX}cpp
ln -s ${PREFIX}g++ ${AFTFIX}g++
ln -s ${PREFIX}gccbug ${AFTFIX}gccbug
ln -s ${PREFIX}gcj ${AFTFIX}gcj
ln -s ${PREFIX}gcov ${AFTFIX}gcov
ln -s ${PREFIX}gdb ${AFTFIX}gdb
ln -s ${PREFIX}gfortran ${AFTFIX}gfortran
ln -s ${PREFIX}gprof ${AFTFIX}gprof
ln -s ${PREFIX}jcf-dump ${AFTFIX}jcf-dump
ln -s ${PREFIX}ld ${AFTFIX}ld
ln -s ${PREFIX}ldd ${AFTFIX}ldd
ln -s ${PREFIX}nm ${AFTFIX}nm
ln -s ${PREFIX}objcopy ${AFTFIX}objcopy
ln -s ${PREFIX}objdump ${AFTFIX}objdump
ln -s ${PREFIX}populate ${AFTFIX}populate
ln -s ${PREFIX}ranlib ${AFTFIX}ranlib
ln -s ${PREFIX}readelf ${AFTFIX}readelf
ln -s ${PREFIX}run ${AFTFIX}run
ln -s ${PREFIX}size ${AFTFIX}size
ln -s ${PREFIX}strings ${AFTFIX}strings
ln -s ${PREFIX}strip ${AFTFIX}strip
寫完這個link.sh文件以后,我們執行一下
sh link.sh
這樣我們就得到了整個使用標准名稱的交叉編譯工具鏈