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`

猜你喜欢

转载自www.cnblogs.com/sansna/p/9261470.html