8

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?

CodeClown42
  • 11,194
  • 1
  • 32
  • 67
  • I am confused about this one as well! I am trying to use crosstool-ng to make a toolchain for my own linux distribution. As far as I can tell, I want my sysroot to simply be "/" as I want to build a toolchain that will be used in the target system as the ONLY toolchain and not for something like cross-compiling. Currently, the resulting toolchain does not even look in standard locations, such as /lib or /usr/lib. Documentation does not even seem to cover my (completely normal?) use case. – Daniele Testa Jul 02 '19 at 11:05
  • @DanieleTesta Why would you use crosstool-ng if you are not building a cross-compiler? If you are not aware of it, you should look at http://www.linuxfromscratch.org/ That should explain how to compile a native compiler, toolchain, and C library from source the conventional way -- it is actually done in stages, using one compiler to build the next as different fundamental parts of the system are also built; see chpt. 5 in particular. I admit to not having read this in quite a few years but am glad to see it is still being maintained and developed, I learnt a lot from it. – CodeClown42 Jul 02 '19 at 13:32
  • Because I am using crosstool-ng to build a toolchain for another arch? Cross-Native build. Using crosstool-ng on a x86 to build a toolchain for ARM that can build ARM-binaries. The resulting toolchain is then moved to my prepared rootfs to be run on the ARM-system. – Daniele Testa Jul 02 '19 at 14:09
  • Sorry I misunderstood your initial comment. Still, I'm not sure that yours really is a "completely normal" one for crosstool-ng, because the normal way (I think) would be to use an existing cross-compiler (x86 -> ARM) to build a native ARM compiler. I think most distros have a packaged cross-compiler for arm v7 and v8. – CodeClown42 Jul 02 '19 at 15:04
  • 1
    Well, it looks normal according to the documentation. They even include cross-native as an option. Look at "option 3, cross-native" here: https://crosstool-ng.github.io/docs/toolchain-types/ – Daniele Testa Jul 02 '19 at 15:15

2 Answers2

5

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
  • 1,470
  • 15
  • 21
2

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.

Frank Liu
  • 1,466
  • 3
  • 23
  • 36