当前位置: 首页 > 工具软件 > crosstool-NG > 使用案例 >

linux编译工具链制作,编译工具链子制作神器 – crosstool-ng

简俊楚
2023-12-01

有很多种方法可以做链子,这里我推荐一个制作交叉链子神器 – 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,完毕。

 类似资料: