When using libclang from Python, it does not seem to automatically look for ways to enable the system.
Is there any reliable way to get these paths? I don't like hard coding paths as I write code that will work on various 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 a system that includes paths by doing
$ clang -v -E test.cpp
and adding "-Isome/path" to the parse argument list, i.e.
args = ["-I/Applications/[...]", "test.cpp"]
It really works and does not cause errors.
However, this is not portable, and it would be very nice if I could programmatically get clang to use them automatically.
c ++ python clang libclang
csl
source share