[cfe-dev] Cross compiling with clang (and sysroot support)

Joerg Sonnenberger joerg at britannica.bec.de
Fri May 17 10:26:02 PDT 2013


On Fri, May 17, 2013 at 05:05:24PM +0200, Stephen Kelly wrote:
> However, there's still a problem. It seems that the term 'sysroot' means 
> different things to clang and gcc.

Clang uses it to specify a system root. Basically, prepare a directory
you would be able to chroot it into. The GNU toolchain is pretty
inconsistent in what it does with the option, so yes, it does mean a
number of different things.

This is made worse by the hundred different approaches for Linux
distributions to set up GCC. I really think we should just start
shipping our own set of the CRT files for Linux...

> If I have to use the sysroot option to tell clang where to find crtX.o 
> files, then I can't use it to tell clang where to find the zlib headers and 
> libraries. They are not in the same location as the crti.o etc. 

No, that should be done with -B.

> Clang also does not search in the arch-specific include dir as gcc does, so 
> it doesn't find sys/types:
>  $ clang -v -target arm-linux-gnueabihf --sysroot /home/stephen/rpi/rasp-pi-
> rootfs/ -B /usr/arm-linux-gnueabihf/lib/ main.c
>  ignoring nonexistent directory "/usr/bin/../lib/clang/3.2/include"
>  ignoring nonexistent directory "/home/stephen/rpi/rasp-pi-
> rootfs//usr/include/x86_64-linux-gnu"

This is a bug in the Debian/Ubuntu workaround. It seems to be looking
for the host triple and not the target triple.

Joerg



More information about the cfe-dev mailing list