Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

crosstool-ng, directory structure, and sysroot

I have a working cross-compiler toolchain, thanks to crosstool-ng :) -- however, crosstool-ng is very sparsely documented, and I am brand new to cross-compiling. The specific host and target are not, I think, important in this context.

I have some basic questions about the directory structure. The toolchain was installed into a directory named after the target. Inside that are a set of directories:

arm-unknown-linux-gnueabi
bin
include
lib
libexec
share

I presume this is for the actual cross-compiler bits, since the compilers in bin/ do work for this purpose. Notice that there is an inner arm-unknown-linux-gnueabi/ directory, ie, the path in there is ../arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi. Inside that there is another tree:

bin
debug-root
include
lib
lib32
lib64
sysroot

The lib* directories are symlinks into sysroot/. The stuff in bin seems to be the same set of cross-compile tools as in the parent directory /bin:

> bin/gcc -v
Using built-in specs.
COLLECT_GCC=./gcc
Target: arm-unknown-linux-gnueabi
Configured with: /usr/x-tool/.build/src/gcc-4.7.2/configure 
--build=x86_64-build_unknown-linux-gnu 
--host=x86_64-build_unknown-linux-gnu 
--target=arm-unknown-linux-gnueabi

So my first question is: what are these for? And what is this directory for?

My second question then is: how should sysroot/ be used? It's apparently for support libraries native to the target platform, so I presume if I were building such a library I should use that as the --prefix, although it would amount to the same thing as using the parent directory, since lib* is symlinked...this "directory in the middle" with a bin and symlinks down to sysroot is confusing. I believe (some) autotools style packages can be configured "--with-sysroot". What is the significance of that, if I see it, and how should it be used in relation to other options such as --prefix, etc?

like image 378
CodeClown42 Avatar asked Feb 09 '13 20:02

CodeClown42


People also ask

What is Sysroot directory?

A sysroot is a directory which is considered to be the root directory for the purpose of locating headers and libraries. So for example if your build toolchain wants to find /usr/include/foo. h but you are cross-compiling and the appropriate foo. h is in /my/other/place/usr/include/foo.

What is Sysroot used for?

A sysroot is a scaled down version of your target's filesystem, it need only contain the libraries and headers which you will compile/link against. There are many ways to set up a sysroot, one is to copy the /usr and /lib directories from your target to somewhere on your host filesystem.


2 Answers

For your first question, as toolchain installed directory:

  • bin/arm-unknown-linux-gnueabi-gcc
  • arm-unknown-linux-gnueabi/bin/gcc

They are the same, indeed hard links.

You can use arm-unknown-linux-gnueabi-gcc by CC=arm-unknown-linux-gnueabi-gcc, e.g.

export PATH=<toolchain installed dir>/bin:$PATH
CC=arm-unknown-linux-gnueabi-gcc ./configure 
make

Or

export PATH=<toolchain installed dir>/arm-unknown-linux-gnueabi/bin:$PATH
./configure 
make

I always used the first form, and I am not sure if the latter form works.

For your second question, in my experience, you don't need to concern about sysroot. cross-compiler will find the correct C header files in sysroot/usr/include automatically.

Except that you want to cross-compile some libraries and install them into sysroot, you can get it by

export PATH=<toolchain installed dir>/bin:$PATH
CC=arm-unknown-linux-gnueabi-gcc ./configure --prefix=<toolchain installed dir>/arm-unknown-linux-gnueabi/arm-unknown-linux-gnueabi/sysroot
make
make install
like image 189
Like Avatar answered Sep 30 '22 03:09

Like


Starting at 38:39 of the talk Anatomy of Cross-Compilation Toolchains by Thomas Petazzoni, the speaker gives an in-depth walk through of the output directory structure.

like image 25
Frank Liu Avatar answered Sep 30 '22 05:09

Frank Liu