Hello,<br><br>I tried to build a clang module by following the tutorial given at: <a href="http://www.cs.rpi.edu/~laprej/clang.html">http://www.cs.rpi.edu/~laprej/clang.html</a><br><br>I have managed to fixed all the compile time errors. However, I have received many link time errors.<br>
<br>The source code, makefile and compile errors are given.<br><br>Can someone please shed some light on it?<br><br>Cheers,<br>Zheng<br clear="all"><br>----------------------------------<br><br>Source:<br><br>#include "clang/Frontend/FrontendActions.h"<br>
#include "clang/AST/ASTConsumer.h"<br>#include "clang/AST/RecursiveASTVisitor.h"<br><br>#include <llvm/Support/raw_ostream.h><br>#include <clang/Basic/Diagnostic.h><br>#include <clang/Basic/TargetInfo.h><br>
#include <clang/Basic/FileManager.h><br>#include <clang/Lex/Preprocessor.h><br>#include <clang/Lex/HeaderSearch.h><br>#include <clang/Frontend/TextDiagnosticPrinter.h><br>#include <clang/Basic/IdentifierTable.h><br>
#include <clang/Driver/Action.h><br>#include <clang/Parse/Parser.h><br>#include <clang/Sema/DeclSpec.h><br>#include <clang/AST/ASTConsumer.h><br>#include <clang/AST/Decl.h><br>#include <clang/AST/DeclGroup.h><br>
#include <clang/Parse/ParseAST.h><br>#include <clang/AST/ASTContext.h><br>#include <clang/Frontend/DiagnosticOptions.h><br>#include <clang/Basic/TargetOptions.h><br><br>#include <cstdio><br>#include <iostream><br>
#include <string><br><br>using namespace clang;<br>using namespace std;<br><br>namespace {<br> class BoostConASTConsumer : public ASTConsumer,<br> public RecursiveASTVisitor<BoostConASTConsumer> {<br>
public:<br> /// HandleTranslationUnit - This method is called when the ASTs for entire<br> /// translation unit have been parsed.<br> virtual void HandleTranslationUnit(ASTContext &Ctx);<br><br> bool VisitCXXRecordDecl(CXXRecordDecl *D) {<br>
std::cout << D->getNameAsString() << std::endl;<br> return true;<br> }<br> };<br>}<br><br>ASTConsumer *BoostConAction::CreateASTConsumer(CompilerInstance &CI,<br> llvm::StringRef InFile) {<br>
return new BoostConASTConsumer();<br>}<br><br>void BoostConASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {<br> fprintf(stderr, "Welcome to BoostCon!\n");<br> TraverseDecl(Ctx.getTranslationUnitDecl());<br>
}<br><br><br>int main(int argc, char** argv)<br>{<br> if (argc < 2)<br> {<br> cerr << "No input file" << endl;<br> exit(-1);<br> }<br><br> TextDiagnosticPrinter tdp(llvm::errs(), DiagnosticOptions());<br>
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());<br> Diagnostic diag(DiagID, &tdp);<br> LangOptions lang;<br> FileSystemOptions FileSystemOpts;<br><br> FileManager fm(FileSystemOpts);<br>
SourceManager sm(diag, fm);<br> //SourceMgr sm;<br> HeaderSearch headers(fm);<br> TargetOptions TargetOpts;<br> TargetInfo *ti = TargetInfo::CreateTargetInfo(diag, TargetOpts);<br> Preprocessor pp(diag, lang, *ti, sm, headers);<br>
<br> //PreprocessorInitOptions ppio;<br> //InitializePreprocessor(pp, ppio);<br><br> const FileEntry *file = fm.getFile(argv[1]);<br> sm.createMainFileID(file);<br><br> IdentifierTable tab(lang);<br>
SelectorTable sel;<br> Builtin::Context builtins(*ti);<br> BoostConASTConsumer c;<br> ASTContext ctx(lang, sm, *ti, tab, sel, builtins, 0);<br> ParseAST(pp, &c, ctx, false, true);<br>
<br> return 0;<br>}<br><br>===========================================================================<br><br>MAKEFILE:<br><br>==============================================================================<br><br>SOURCE=BoostConAction.cpp<br>
OBJ=$(SOURCE:.cpp=.o)<br>TARGET=bca<br><br>all:${TARGET}<br><br>${TARGET}:${OBJ}<br> g++ `llvm-config --ldflags --libs` -lclangBasic -lclangLex -lclangDriver -lclangFrontend -lclangParse \<br> -lclangAST -lclangSema -lclangAnalysis -lclang -o ${TARGET} ${OBJ}<br>
<br>${OBJ}:${SOURCE}<br> g++ -g -fno-rtti `llvm-config --cxxflags` -c ${SOURCE}<br><br>clean:<br> rm -f ${OBJ} ${TARGET}<br><br>=======================================================================================<br>
<br>ERRORS<br><br>=========================================================================================<br><br>g++ -g -fno-rtti `llvm-config --cxxflags` -c BoostConAction.cpp<br>g++ `llvm-config --ldflags --libs` -lclangBasic -lclangLex -lclangDriver -lclangFrontend -lclangParse \<br>
-lclangAST -lclangSema -lclangAnalysis -lclang -o bca BoostConAction.o<br>BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseParmVarDecl(clang::ParmVarDecl*)':<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1600: undefined reference to `clang::ParmVarDecl::getDefaultArg()'<br>BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseDeclContextHelper(clang::DeclContext*)':<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1049: undefined reference to `clang::DeclContext::decls_begin() const'<br>/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1050: undefined reference to `clang::DeclContext::decls_end() const'<br>
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc)':<br>/workspace/build/include/clang/AST/RecursiveASTVisitor.h:532: undefined reference to `clang::NestedNameSpecifier::getKind() const'<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:541: undefined reference to `clang::NestedNameSpecifierLoc::getTypeLoc() const'<br>BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseNestedNameSpecifier(clang::NestedNameSpecifier*)':<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:508: undefined reference to `clang::NestedNameSpecifier::getKind() const'<br>BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseObjCMessageExpr(clang::ObjCMessageExpr*)':<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1871: undefined reference to `clang::ObjCMessageExpr::children()'<br>BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseUnaryExprOrTypeTraitExpr(clang::UnaryExprOrTypeTraitExpr*)':<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1790: undefined reference to `clang::UnaryExprOrTypeTraitExpr::children()'<br>BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseClassTemplateSpecializationDecl(clang::ClassTemplateSpecializationDecl*)':<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1407: undefined reference to `clang::CXXRecordDecl::getTemplateSpecializationKind() const'<br>BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseFunctionInstantiations(clang::FunctionTemplateDecl*)':<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1284: undefined reference to `clang::FunctionDecl::getTemplateSpecializationKind() const'<br>BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl*)':<br>
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1437: undefined reference to `clang::ClassTemplateSpecializationDecl::getSpecializedTemplate() const'<br>BoostConAction.o: In function `main':<br>....<br><br>