Crossbuild: with crosstool-ng

Before preceding, several things need to be checked:

  1. Which and where is the interpreter on the target machine am I going to use (get its name & version)? (Or not using any?)
  2. Is the program dynamic linked or statically linked, and if dyn, do all needed libs exist on target machine? If not exist, where to put them?
  3. If some shared libs exist on machine, do versions match (try best to match)?

There are too many tutorials on how to build with ct-ng, I only list several useful steps for future reference.

# ct-ng cannot be run as root
git clone crosstool-NG
cd crosstool-NG
./configure --enable-local --with-ncurses --with-bash-completion #--prefix=/usr
make -j [N]
cp bash-completion/ct-ng /etc/bash_completion.d/
# source bash_completion ....
./ct-ng list-samples
# use pre-set default .config file
./ct-ng show-arm-unknown-linux-gnueabi 
# modify based on the .config file
./ct-ng menuconfig
# build toolchain, destdir is $HOME/x-tools/
./ct-ng build

After that a whole toolchain for certain architecture has been built.

If need to compile some program with this toolchain, in the directory where we normally issue "./configure; make ; sudo make install", we do the following:

export PATH=$PATH:$HOME/x-tools/arm-unknown-linux-gnueabi/bin # Where all the tools prefixed with arm-unknown-linux-gnueabi lays
CFLAGS="..." LDFLAGS="..." ./configure --prefix=/usr --host=arm-unknown-linux-gnueabi make -j [N] DESTDIR=... make install

Some frequently used flags:

CFLAGS="-I/home/sansna/src/src1/build/usr/include -I/home/sansna/src/src2/build/usr/include"

LDFLAGS="-Wl,-I,/opt/ld-linux.so.3 -Wl,-rpath,/opt/lib/ -L/home/sansna/src/src1/build/usr/lib -L/home/sansna/src/src2/build/usr/lib"

----

At last, note that crosstool-ng support linux kernel version newer than 3.2.101; glibc version newer than 2.12.1(or uClibc newer than 1.0.25); gcc version newer than 4.9.4; also support java/cxx/fortran; binutils version newer than 2.26.1.

It also support specify ldflags and cflags. (Wow!)

How to use crosstool-ldd? Specify a sysroot correctly with --root. In the above example, try:

arm-unknown-linux-gnueabi-ldd --root=`arm-unknown-linux-gnueabi-gcc --print-sysroot`

------all tools used to create itself needs bootstrapping----

What is bootstrap, and why do we need bootstrap while building ct-ng? According to here.

A bootstrap is using the old tool to create pass-1 tool using new src, and then using the pass-1 tool to create pass-2 tool using the same new src, and using the pass-2 tool to create a third pass-3 tool again to compare differences between pass-2 and pass-3. If no diff, the pass-3 is called final. Otherwise some bugs may exist.

转载于:https://www.cnblogs.com/sansna/p/9261470.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值