link order for libtooling


What is the order of the clang libraries when linking?

Currently I'm doing:

clang++ -fno-rtti `llvm-config --cxxflags` \
  iterate.cpp \
  `llvm-config --ldflags --libs --system-libs` \
  -I/usr/lib/llvm-3.8/include -ggdb3 -std=c++11 -I/usr/include/llvm-3.8/llvm/Support -L/usr/lib/llvm-3.8/lib/ -L/usr/lib/gcc/x86_64-linux-gnu/5/ -I/usr/include/c++/5/ -I/usr/include/x86_64-linux-gnu/c++/5/ -I/usr/lib/llvm-3.8/include/ \
  -lclangTooling -lclangFrontend -lclangDriver -lclangSerialization -lclangParse -lclangSema -lclangAnalysis -lclangEdit -lclangAST -lclangLex -lclangBasic -lLLVM -ldl

but this gives me:

/tmp/iterate-66d196.o: In function `getNameAsString':
/usr/lib/llvm-3.8/include/clang/AST/Decl.h:184: undefined reference to `clang::DeclarationName::getAsString() const'

Thanks in advance.

Folkert van Heusden

In ESBMC [0], we use:

-lclangTooling -lclangDriver -lclangFrontend -lclangParse -lclangSerialization -lclangSema -lclangAnalysis -lclangEdit -lclangLex -lclangAST -lclangBasic -lLLVMBitReader -lLLVMCore -lLLVMOption -lLLVMMCParser -lLLVMMC -lLLVMSupport -lrt -ldl -lpthread -lz -lm

For clang, we have to manually write the libs, but for llvm we simply use llvm-config, you can check the scripts for clang’s libs [1] and llvm [2].


Problem with getName() is that it does not exist for too many types.
For example when I have a QualType that I would like to get as a string,
then the doxygen says there's a getAstString static function but in
reality it is not there. There's also no getName() for QualType. Then
there's the split() method but the object that comes out of it also has
no tostring or something that emits an enum or something.

What I'm trying to do is create a tool which emits an xml of the ast.
A bit like the one which was included.

Hi Folkert,

getName() should work for namedDecl only; to get type names, you need to work differently.

I suggest you have a look at:

They print/dump the AST. I would say it’s the best place to look (and reimplement) to print a xml.