How to Compile Clang Libtooling Programs Under Bionic?

How to Compile Clang Libtooling Programs Under Bionic?

I'm trying to port a project that uses Clang's LibTooling library from Arch to Ubuntu/Debian. I have installed the clang-10, llvm-10 and libclang-10-dev packages. The latter installs the necessary headers to /usr/lib/llvm-10/include/clang/ (i.e. usr/lib/llvm-10/include/clang/Tooling/Tooling.h). However, trying to link a program that uses these headers results in various linking errors such as:

undefined reference to `clang::ast_matchers::internal::DynTypedMatcher::matches(clang::ast_type_traits::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const'

Under Arch I can resolve this with -lclang-cpp but no such library exists under Ubuntu. Several posts on StackOverflow recommend linking to various other libraries, so I have als tried:

-lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewriteFrontend -lclangEdit -lclangAST -lclangLex -lclangBasic

But that does not work either. Are the libclang-*-dev packages incomplete/broken? Am I missing yet another package? Or am I just linking against the wrong libraries?

4
David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.