After migrating the C++ parser to libclang , we expected to see a perfectly accurate Abstract Syntax Tree (AST). But when we unleashed it on our first real project, instead of a beautiful hierarchy of classes, we got a tree consisting entirely of CXCursor_UnexposedDecl and fatal syntax errors.
The parser stumbled on the very first line: #include <vector> .
A Deaf Compiler
It turned out that libclang (being merely a linkable library, not a full CLI compiler) by default has no idea where standard header files are located in the operating system.
If the parser doesn't see system headers, it doesn't understand what std::string or std::vector is. And since everything in modern C++ relies on standard library templates, parsing fails in a cascade.
In the Enterprise world, developers usually pass giant strings of -I/usr/include/... flags to the parsers themselves. But we were building a SaaS and a user-friendly CLI utility. We couldn't force users to manually search for compiler paths on their machines.…