Hello, I’m trying to figure out the right set of flags to pass to libclang C API to get it to parse a simple file correctly.
I have the clang+llvm package installed on my Ubuntu 20.04 (under WSL2) to:
/home/anders/packages/llvm/14.0.0
and I’m trying to inspect the AST for this simple example:
#include <stddef.h>
const size_t a = 0;
If I just pass the following arguments to clang_parseTranslationUnit()
:
"-std=c++14",
"-x", "c++",
then I get the following error:
testdata/test_size_t.cpp:1:10: fatal error: 'stddef.h' file not found
Ok, no problem, I’ll add the c++ includes from the clang installation:
"-std=c++14",
"-x", "c++",
"-isystem/home/anders/packages/llvm/14.0.0/include/c++/v1/",
"-isystem/home/anders/packages/llvm/14.0.0/include/x86_64-unknown-linux-gnu/c++/v1/",
This now gives me:
/home/anders/packages/llvm/14.0.0/include/c++/v1/stddef.h:45:15: fatal error: 'stddef.h' file not found
I have two other stddef.h’s on my system, one in /usr/include/linux' and another in
/usr/lib/gcc/x86_64-linux-gnu/9/include. The one in in
/usr/include/linux` is empty, so adding that to the include path gives me:
testdata/test_size_t.cpp:3:7: error: unknown type name 'size_t'
And the one in /usr/lib/gcc...
appears to work (at least no more diagnostic errors), but it feels like I’m mixing and matching clang and gcc here. My final set of args is:
"-std=c++14",
"-x", "c++",
"-isystem/home/anders/packages/llvm/14.0.0/include/c++/v1/",
"-isystem/home/anders/packages/llvm/14.0.0/include/x86_64-unknown-linux-gnu/c++/v1/",
"-isystem/usr/lib/gcc/x86_64-linux-gnu/9/include/"
Are there any more I should have as a “base” set before adding project-specific ones? are these even correct?