How to get Clang's include directory name?

10,608 views
Skip to first unread message

Denis Glotov

unread,
Oct 27, 2011, 9:53:18 AM10/27/11
to Nico Weber, cl...@chromium.org
Hi devs!

I wonder is there an easy method to automatically get Clang's own include directory. Currently it is $CLANG_BASE/../lib/clang/3.1/include, but may change, for example, when 3.1 becomes 3.2.

I can use `clang++ -v -xc++ -` output and parse, but it looks unreasonably complex. Is there a more straight-forward method, like gcc-config for gcc?

--
Thank you,
Denis

Nico Weber

unread,
Oct 27, 2011, 12:02:43 PM10/27/11
to Denis Glotov, cl...@chromium.org
What do you need it for? Clang automatically adds it as an include
path, and I think it's considered an implementation detail.

What are you trying to do? :-)

Nico

Denis Glotov

unread,
Oct 27, 2011, 12:48:36 PM10/27/11
to Nico Weber, cl...@chromium.org
Huh, I need it for the following.

The problem:
1. The file cxxabi.h is required for building Chrome (gTest and Webkit needs it now).
2. It is stored under libstlc++'s directory ${CXX_PATH}/include/cxxabi.h.
3. But if I add this folder to clang with -I<include-dir>, it will take another header (${CXX_PATH}/include/xmmintrin.h) from there, while it should have been taken from $CLANG_BASE/../lib/clang/3.1/include.
4. This produces a lot of errors in xmmintrin.h.
5. No matter what order I put -I options. They are always preferred to $CLANG_BASE/../lib/clang/3.1/include.

My solution:
1. I do not pass -I${CXX_PATH}/include to Clang.
2. I make a symlink $CLANG_BASE/../lib/clang/3.1/include/cxxabi.h that points to the libstlc++'s original.

So, to always make a symlink correctly, I need to know where it should be :)

If you have any better idea how to overcome this cxxabi/xmmintrin chaos, please advice.

--
Thank you,
Denis

Nico Weber

unread,
Oct 27, 2011, 1:10:15 PM10/27/11
to Denis Glotov, cl...@chromium.org
#includeing cxxabi.h works fine for me, on linux and mac:

thakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$ echo
'#include <cxxabi.h>' >
test.ccthakis@yearofthelinuxdesktop:/usr/local/google/chrome/src$
third_party/llvm-build/Release+Asserts/bin/clang --verbose -c
test.ccclang version 3.1 (trunk 142664)Target:
x86_64-unknown-linux-gnuThread model: posix
"/usr/local/google/chrome/src/third_party/llvm-build/Release+Asserts/bin/clang"
-cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all
-disable-free -main-file-name test.cc -mrelocation-model static
-mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables
-target-cpu x86-64 -target-linker-version 2.20.1
-momit-leaf-frame-pointer -v -coverage-file test.o -resource-dir
/usr/local/google/chrome/src/third_party/llvm-build/Release+Asserts/bin/../lib/clang/3.1
-fmodule-cache-path /var/tmp/clang-module-cache -fdeprecated-macro
-fdebug-compilation-dir /usr/local/google/chrome/src -ferror-limit 19
-fmessage-length 205 -fgnu-runtime -fobjc-runtime-has-arc
-fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions
-fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o test.o
-x c++ test.ccclang -cc1 version 3.1 based upon llvm 3.1svn hosted on
x86_64-unknown-linux-gnuignoring nonexistent directory (long list)
ignoring duplicate directory (long list)
#include "..." search starts here:
#include <...> search starts here: /usr/include/c++/4.4
/usr/include/c++/4.4/backward /usr/include/c++/4.4/x86_64-linux-gnu/
/usr/local/include
/usr/local/google/chrome/src/third_party/llvm-build/Release+Asserts/bin/../lib/clang/3.1/include
/usr/includeEnd of search list.


I don't have xmmintr.h below /usr/include on my system – it's in
/usr/lib/gcc. It sounds like you might have your gcc and libstd
include paths mixed up somehow?

Denis Glotov

unread,
Oct 27, 2011, 1:40:11 PM10/27/11
to Nico Weber, cl...@chromium.org
No, xmmintr.h, the gcc's version, is in libstlc++: /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.X/include/xmmintrin.h,
while the Clang's version is here (if Clang is installed to /usr/bin): /usr/lib/clang/3.1/include/xmmintrin.h.

So, if I -I/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.X/include, the Clang will get gcc's version of xmmintrin.h.

--
Thank you,
Denis

Nico Weber

unread,
Oct 27, 2011, 1:48:24 PM10/27/11
to Denis Glotov, cl...@chromium.org
On Thu, Oct 27, 2011 at 10:40 AM, Denis Glotov <glo...@google.com> wrote:
> No, xmmintr.h, the gcc's version, is in
> libstlc++: /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.X/include/xmmintrin.h,

Yes, but cxxabi.h is in /usr/lib/c++, right? So don't add /usr/lib/gcc
to your search path.

Denis Glotov

unread,
Oct 27, 2011, 1:54:11 PM10/27/11
to Nico Weber, cl...@chromium.org
Hm, currently I add the following paths: 
#!/bin/sh
exec clang++.real "\$@" \
-I${CXX_PATH}/include-fixed \
-I${CXX_PATH}/include/g++-v4 \
-I${CXX_PATH}/include/g++-v4/x86_64-pc-linux-gnu \
-I${CXX_PATH}/include/g++-v4/backward

where CXX_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.X.

If I stop adding them, Chrome will not find STL.

Or did I get you wrong again?
--
Thank you,
Denis

Nico Weber

unread,
Oct 27, 2011, 2:01:59 PM10/27/11
to Denis Glotov, cl...@chromium.org
On Thu, Oct 27, 2011 at 10:54 AM, Denis Glotov <glo...@google.com> wrote:
> Hm, currently I add the following paths:
> #!/bin/sh
> exec clang++.real "\$@" \
> -I${CXX_PATH}/include-fixed \
> -I${CXX_PATH}/include/g++-v4 \
> -I${CXX_PATH}/include/g++-v4/x86_64-pc-linux-gnu \
> -I${CXX_PATH}/include/g++-v4/backward
> where CXX_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.X.
> If I stop adding them, Chrome will not find STL.

I don't know how the gentoo directory layout looks, but they will
probably put libstdc++ headers in a different directory than the gcc
internal compiler headers. Only add the former to your search path. On
my ubuntu box, this works out of the box.

Denis Glotov

unread,
Oct 27, 2011, 2:45:39 PM10/27/11
to Nico Weber, cl...@chromium.org
Nico, so where did your Clang find cxxabi.h?
--
Thank you,
Denis

Nico Weber

unread,
Oct 27, 2011, 3:08:53 PM10/27/11
to Denis Glotov, cl...@chromium.org
thakis@yearofthelinuxdesktop:~$ find /usr/include -name
'cxxabi.h'/usr/include/c++/4.4/cxxabi.hthakis@yearofthelinuxdesktop:~$
find  /usr/lib/gcc -name
'*xmmintrin*'/usr/lib/gcc/x86_64-linux-gnu/4.4/include/xmmintrin.h

Denis Glotov

unread,
Oct 27, 2011, 3:36:56 PM10/27/11
to Nico Weber, cl...@chromium.org
So the problem is the following:

If I add -I${CXX_PATH}/include, I get the error about xmmintrin.h,
If I don't - I get the error that cxxabi.h is not found.

My Clang have the following include paths by default (not counting -I's that I add):
#include <...> search starts here:
 /usr/local/include
 /usr/bin/../lib/clang/3.1/include
 /usr/include
End of search list.

So it have no chance to locate ${CXX_PATH}/include/cxxabi.h by default. So I workaround it by making a symlink.


BTW, Nico, your code snippets are unreadable. Not sure why, but one lines end combines with next lines beginning. Could you please set the font to fixed, for example, to overcome that?

BTW2, I discovered that don't need to pass -I${CXX_PATH}/include-fixed. This is a good side-effect of our conversation :)
--
Thank you,
Denis
Reply all
Reply to author
Forward
Message has been deleted
0 new messages