Clang command line options

Hi,
   I am creating a clang tool and passing some custom command line options.
When I pass something using -I option, clang searches the directories
recursively, but when I pass something using the -isystem option, it
doesn't. e.g. When I pass the system header using "/usr/include/c++/4.7", it
searches in all folders inside 4.7 too. But when i pass it using "-isystem
/usr/include/c++/4.7", it doesn't search inside the system headers and
instead gives an error "#include "stdarg.h" not found". Why is this
happening? The gcc manual says that both command work exactly the same. The
only difference is that one marks files as system headers while the other
doesn't.

Regards,
Adil

Short answer: <stdarg.h> is not found in that directory.

Long answer: Clang (and the clang libraries) looks for <stdarg.h> and (other compiler-provided headers) in a hardcoded directory relative the the current executable. If your executable is not sitting inside alongside clang inside a clang installation dir or build dir, then the hardcoded path that it looks for won’t contain the right headers (if your tool is in such a directory, then I have probably misdiagnosed your issue; I apologize). This has been a pain point for a long time and needs to be fixed, but we have not reached a consensus about the best way to go about it. <http://clang.llvm.org/docs/FAQ.html> will give you some insight into the issue.

Dmitri, could you please update/rework <http://clang.llvm.org/docs/FAQ.html> so that it covers the way that madil90 has posed this question (regardless of whether or not I diagnosed this issue correctly)? Maybe we should have a dedicated question why does clang not find some headers like "stddef.h" or "stdarg.h"? The content should be written to fill the use case where we reply to these built-in header questions by just linking to the FAQ and have that give the user a useful understanding of the issue (and what they can do about it, and that they are not alone).

– Sean Silva

You interpreted the question correctly. My executable is not present in the clang directory and therefore I was getting one path wrong, which soon became apparent from the verbose output. For the time being I have added the path through command line. I am interested in compiler theory and would like to know why this problem is taking so long to fix? What are the possible options and why makes it so hard to choose one? Thank you very much for your help.

Regards,
Adil

We already have that explained here:
http://clang.llvm.org/docs/LibTooling.html#builtin-includes

I don't feel comfortable copying that text to FAQ...

Dmitri

It could be referenced from the FAQ ?

John Smith

Makes sense. Is r174612 good enough?

Dmitri