When using libclang from Python, it doesn't seem to automatically search the system's include paths.
Is there a reliable way to get these paths? I don't like hardcoding paths as I'm writing code that will run on a variety of UNIX systems.
For example, given test.cpp
#include <stdio.h>
int main()
{
puts("Hello, world!");
}
and test.py
from clang.cindex import Index
tu = Index.create().parse(None, ["test.cpp"])
print(list(tu.diagnostics))
running python test.py
will print:
[<Diagnostic severity 4, location <SourceLocation file 'test.cpp', line 1,
column 10>, spelling "'stdio.h' file not found">]
Of course, I can find the system include paths by doing
$ clang -v -E test.cpp
and adding "-Isome/path"
to the parse
argument-list, i.e.
args = ["-I/Applications/[...]", "test.cpp"]
That actually works and produces no errors.
However, this isn't portable, and it would be really nice if I could programmatically get clang to automatically use them.