Cannot compile program when using the AnalysisManager

Hi,
I am new to clang. I was trying to invoke the AnalysisManager object and use it in a program. I am quoting relevant parts of the code.

CXIndex index = clang_createIndex(1, 0);
CXTranslationUnit tu = clang_createTranslationUnitFromSourceFile(index,
“simple.c”, 0, 0x0, 0, 0x0);
ASTUnit *astUnit = static_cast<ASTUnit > (tu);
Preprocessor &pe = astUnit->getPreprocessor();
AnalysisManager AMgr(astUnit->getASTContext(), pe.getDiagnostics(),
pe.getLangOptions(), 0,
0,
0, &Idxer,
/
MaxNodes / 300, / MaxVisit / 3,
/
VisualizeEG / false, / VisualizeEGUbi / false,
/
PurgeDead / true, / EagerlyAssume / false,
/
TrimGraph / false, / InlineCall / true,
/
UseUnoptimizedCFG */ false, false, false);

Now, I am compiling the program with the following command.

g++ -O2 -g -Wall -fmessage-length=0 -D __STDC_LIMIT_MACROS=1 -D __STDC_CONSTANT_MACROS=1 -I/home/munawar/install/llvm/tools/clang/tools/libclang -o llvmTest llvmTest.o /home/munawar/install/llvm_build/tools/clang/tools/libclang/Release+Asserts/CIndex.o /home/munawar/install/llvm_build/tools/clang/tools/libclang/Release+Asserts/CXCursor.o /home/munawar/install/llvm_build/tools/clang/tools/libclang/Release+Asserts/CXType.o /home/munawar/install/llvm_build/tools/clang/tools/libclang/Release+Asserts/CIndexer.o /home/munawar/install/llvm_build/tools/clang/tools/libclang/Release+Asserts/CIndexDiagnostic.o /home/munawar/install/llvm_build/tools/clang/tools/libclang/Release+Asserts/CIndexUSRs.o -lclangIndex -lclangChecker -lclangFrontend -lclangSema -lclangLex -lclangParse -lclangDriver -lclangAnalysis -lclangSerialization -lclangAST -lclangBasic -lLLVMMC -lLLVMCore -lLLVMSupport -lLLVMSystem -lpthread -ldl

The interesting and probably relevant part is the library sequence.

-lclangIndex -lclangChecker -lclangFrontend -lclangSema -lclangLex -lclangParse -lclangDriver -lclangAnalysis -lclangSerialization -lclangAST -lclangBasic -lLLVMMC -lLLVMCore -lLLVMSupport -lLLVMSystem -lpthread -ldl

But I am getting this error,

llvmTest.o:(.rodata._ZTIN5clang15AnalysisManagerE[typeinfo for clang::AnalysisManager]+0x8): undefined reference to `typeinfo for clang::BugReporterData’
collect2: ld returned 1 exit status

Can you please point out where I am making a mistake ? Thanks.

Munawar

Did you compile your entire project with -fno-rtti? It smells like the linker is trying to find RTII information for BugReporterData, but it wasn't compiled in. The LLVM libraries by default don't have RTTI information compiled in.

I rebuilt the llvm libraries with REQUIRES_RTTI=1 option in the command line, and it worked like a charm.

Thanks a lot Ted.

Munawar