編譯工具鏈子制作神器 – crosstool-ng

有很多種方法可以做鏈子,這里我推薦一個制作交叉鏈子神器 – crosstool-ng
ct-ng 告別了過去制作交叉鏈子復雜的過程,把制作交叉鏈子做成了一套自動化部署工具,沒有門檻,想怎么改就怎么改。如果在配合buildroot 或者 ptxdist,簡直分分鐘做出一套屬于自己的Linux Embedded 發行版呀有木有。咳咳,制造發行版的這個事情我們后面在來care,下面我們來看看怎么利用神器制作自己的交叉鏈子。
國際慣例先裝基礎環境,這里我用Debian來做。

sudo apt-get install -y git gcc g++ bison gdb binutils bzip2 flex python perl make grep diffutils gettext unzip automake gawk subversion zlib1g-dev libz-dev asciidoc golang curl gperf libtool libtool-bin help2man sed dpkg-dev bison flex patch texinfo automake m4  lzma bison flex texinfo patch gawk python-pip python-m2cryptolibssl1.0.0/jessie libssl-dev/jessie openssl/jessie

crosstool-ng版本眾多,這里我們選用最新的版本。直接從Github拉取最新代碼。
下面的命令不要用root執行。

mkdir $HOME/build
cd $HOME/build
git clone https://github.com/crosstool-ng/crosstool-ng
cd crosstool-ng
./bootstrap
./configure --prefix=$HOME/.local
make
make install
cd ../

加入~/.profile

echo -ne "\n\nif [ -d "$HOME/.local/bin" ]; then\n PATH="$HOME/.local/bin:$PATH"\nfi" >> ~/.profile

使之生效

source ~/.profile

創建工具鏈目錄

mkdir $HOME/tc/ && cd $HOME/tc/

開始創建工具鏈并編譯,這里以mipsel為例:

mkdir mipsel-superman-linux-gnu
cd mipsel-superman-linux-gnu
ct-ng mipsel-unknown-linux-gnu
#設置
ct-ng menuconfig
ct-ng build

等編譯完,你就得到了mipsel的交叉編譯工具鏈。

為了方便,我們進入工具目錄創建軟連接。

cd ${HOME}/x-tools/mipsel-superman-linux-gnu/bin

vi link.sh 輸入

#!/bin/sh
PREFIX=mipsel-superman-linux-gnu-
AFTFIX=mipsel-linux-
ln -s ${PREFIX}addr2line ${AFTFIX}addr2line
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}cc ${AFTFIX}cc
ln -s  ${PREFIX}cpp ${AFTFIX}cpp
ln -s ${PREFIX}ct-ng.config ${AFTFIX}ct-ng.config
ln -s ${PREFIX}elfedit ${AFTFIX}elfedit
ln -s  ${PREFIX}g++ ${AFTFIX}g++
ln -s ${PREFIX}gcc ${AFTFIX}gcc
ln -s ${PREFIX}gcc-6.3.0 ${AFTFIX}gcc-6.3.0
ln -s  ${PREFIX}gcc-ar ${AFTFIX}gcc-ar
ln -s  ${PREFIX}gcc-nm ${AFTFIX}gcc-nm
ln -s  ${PREFIX}gcc-ranlib ${AFTFIX}gcc-ranlib
ln -s  ${PREFIX}gcov ${AFTFIX}gcov
ln -s  ${PREFIX}gcov-tool ${AFTFIX}gcov-tool
ln -s  ${PREFIX}gdb ${AFTFIX}gdb
ln -s  ${PREFIX}gprof ${AFTFIX}gprof
ln -s  ${PREFIX}ld ${AFTFIX}ld
ln -s  ${PREFIX}ld.bfd ${AFTFIX}ld.bfd
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}size ${AFTFIX}size
ln -s  ${PREFIX}strings ${AFTFIX}strings
ln -s  ${PREFIX}strip ${AFTFIX}strip

保存后執行

chmod +x ./link.sh
./link.sh

接著 執行

export PATH="${PATH}:${HOME}/x-tools/mipsel-superman-linux-gnu/bin"

加入系統路徑就可以開始交叉編譯了。

每次執行交叉編譯都要執行上面export這句。

OK,完畢。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容