[cfe-users] --sysroot and --gcc-toolchain: any docs etc.?

Paul Smith via cfe-users cfe-users at lists.llvm.org
Tue Jun 13 05:55:32 PDT 2017


Can someone point to any detailed information about how these flags
work?  I have a custom-compiled version of GCC on Linux and I'm trying
to build Clang 4.0.0 for this system as well.  I would like it to use
libstdc++ from my custom-compiled GCC installation to allow linking of
other libraries built with libstdc++.

I also have a sysroot that I use with GCC so it compiles against a known
set of system headers and libraries (based on Red Hat 6.3 in this case).
 This sysroot is directly extracted from a Red Hat system (technically,
it's extracted from the RPMs) so the layout is straightforward and using
the --sysroot for GCC locates it without any problems.

However, I can't get clang to work with either of these environments no
matter what options I provide it.

For --sysroot for example, I have this:

  /my/sysroot/lib
  /my/sysroot/lib64
  /my/sysroot/usr/include
  /my/sysroot/usr/lib
  /my/sysroot/usr/lib64
  /my/sysroot/usr/libexec

If I use "gcc --sysroot=/my/sysroot" all works fine.  If I use "clang
--syroot=mysysroot" no system headers are found.  I used strace on the
clang binary to try to figure out what it's looking for and it searches
for all of these things in my sysroot directory:

  /my/sysroot/usr/local/cuda
  /my/sysroot/usr/local/cuda-8.0
  /my/sysroot/usr/local/cuda-7.5
  /my/sysroot/usr/local/cuda-7.0
  /my/sysroot/lib/x86_64-linux-gnu
  /my/sysroot/lib/x86_64-generic-linux-gnu
> /my/sysroot/lib/../lib64
  /my/sysroot/usr/lib/x86_64-generic-linux-gnu
> /my/sysroot/usr/lib/../lib64
  /my/sysroot/usr/lib/x86_64-generic-linux-gnu/../../lib64
> /my/sysroot/lib
> /my/sysroot/usr/lib

Of these only the four marked exist in my sysroot.  But the big thing
here is that at no time does clang look for /my/sysroot/usr/include, and
indeed when the preprocessor tries to find headers it doesn't look
there, and none of my system header files are found!

Do I have to add these myself with -isystem even when I specify
--sysroot and the header directory is right there?  Is --sysroot not
intended to be used to locate header files?


For --gcc-toolchain the situation is similar although clang looks in
MANY more places to try to locate the GCC toolchain.  However, I build
GCC myself and I have a completely standard installation: what you get
when you run make / make install after a configure --prefix.  My GCC
installation looks like:

  /my/gcc/bin
  /my/gcc/lib/gcc/x86_64-generic-linux-gnu/7.1.0/include
  /my/gcc/lib64
  /my/gcc/libexec/gcc/x86_64-generic-linux-gnu/7.1.0
  /my/gcc/x86_64-generic-linux-gnu/bin
  /my/gcc/x86_64-generic-linux-gnu/include/c++/7.1.0/...
  /my/gcc/x86_64-generic-linux-gnu/include/c++/7.1.0/x86_64-generic-linux-gnu/...
  /my/gcc/x86_64-generic-linux-gnu/lib
  /my/gcc/x86_64-generic-linux-gnu/lib64

(I have a GCC 6.2 install too and the layout is basically identical.)
When I use --gcc-toolchain with clang it looks in about 50 different
directories but doesn't seem to be able to locate this: a standard
unmodified installation of GCC.  I've tried numerous different values
for --gcc-toolchain but none seem to work.


Am I doing something wrong here?  Or is this just not going to work and
I'll have to figure out all the include directories, etc. I need by hand
and add them via -isystem etc. myself?


Thanks for any help you can provide!



More information about the cfe-users mailing list