clang link errors

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

clang link errors

Zheng Wang
Hello,

I tried to build a clang module by following the tutorial given at: http://www.cs.rpi.edu/~laprej/clang.html

I have managed to fixed all the compile time errors. However, I have received many link time errors.

The source code, makefile and compile errors are given.

Can someone please shed some light on it?

Cheers,
Zheng

----------------------------------

Source:

#include "clang/Frontend/FrontendActions.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"

#include <llvm/Support/raw_ostream.h>
#include <clang/Basic/Diagnostic.h>
#include <clang/Basic/TargetInfo.h>
#include <clang/Basic/FileManager.h>
#include <clang/Lex/Preprocessor.h>
#include <clang/Lex/HeaderSearch.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Basic/IdentifierTable.h>
#include <clang/Driver/Action.h>
#include <clang/Parse/Parser.h>
#include <clang/Sema/DeclSpec.h>
#include <clang/AST/ASTConsumer.h>
#include <clang/AST/Decl.h>
#include <clang/AST/DeclGroup.h>
#include <clang/Parse/ParseAST.h>
#include <clang/AST/ASTContext.h>
#include <clang/Frontend/DiagnosticOptions.h>
#include <clang/Basic/TargetOptions.h>

#include <cstdio>
#include <iostream>
#include <string>

using namespace clang;
using namespace std;

namespace {
  class BoostConASTConsumer : public ASTConsumer,
                              public RecursiveASTVisitor<BoostConASTConsumer> {
  public:
    /// HandleTranslationUnit - This method is called when the ASTs for entire
    /// translation unit have been parsed.
    virtual void HandleTranslationUnit(ASTContext &Ctx);

    bool VisitCXXRecordDecl(CXXRecordDecl *D) {
      std::cout << D->getNameAsString() << std::endl;
      return true;
  }
  };
}

ASTConsumer *BoostConAction::CreateASTConsumer(CompilerInstance &CI,
                                               llvm::StringRef InFile) {
  return new BoostConASTConsumer();
}

void BoostConASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
  fprintf(stderr, "Welcome to BoostCon!\n");
  TraverseDecl(Ctx.getTranslationUnitDecl());
}


int main(int argc, char** argv)
{
        if (argc < 2)
        {
                cerr << "No input file" << endl;
                exit(-1);
        }

        TextDiagnosticPrinter tdp(llvm::errs(), DiagnosticOptions());
        llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
        Diagnostic diag(DiagID, &tdp);
        LangOptions lang;
        FileSystemOptions FileSystemOpts;

        FileManager fm(FileSystemOpts);
        SourceManager sm(diag, fm);
        //SourceMgr sm;
        HeaderSearch headers(fm);
        TargetOptions TargetOpts;
        TargetInfo *ti = TargetInfo::CreateTargetInfo(diag, TargetOpts);
        Preprocessor pp(diag, lang, *ti, sm, headers);

        //PreprocessorInitOptions ppio;
        //InitializePreprocessor(pp, ppio);

        const FileEntry *file = fm.getFile(argv[1]);
        sm.createMainFileID(file);

        IdentifierTable tab(lang);
        SelectorTable sel;
        Builtin::Context builtins(*ti);
        BoostConASTConsumer c;
        ASTContext ctx(lang, sm, *ti, tab, sel, builtins, 0);
        ParseAST(pp, &c, ctx, false, true);

        return 0;
}

===========================================================================

MAKEFILE:

==============================================================================

SOURCE=BoostConAction.cpp
OBJ=$(SOURCE:.cpp=.o)
TARGET=bca

all:${TARGET}

${TARGET}:${OBJ}
        g++ `llvm-config --ldflags --libs` -lclangBasic -lclangLex -lclangDriver -lclangFrontend -lclangParse \
        -lclangAST -lclangSema -lclangAnalysis -lclang -o ${TARGET} ${OBJ}

${OBJ}:${SOURCE}
        g++ -g -fno-rtti `llvm-config --cxxflags` -c ${SOURCE}

clean:
        rm -f ${OBJ} ${TARGET}

=======================================================================================

ERRORS

=========================================================================================

g++ -g -fno-rtti `llvm-config --cxxflags` -c BoostConAction.cpp
g++ `llvm-config --ldflags --libs` -lclangBasic -lclangLex -lclangDriver -lclangFrontend -lclangParse \
        -lclangAST -lclangSema -lclangAnalysis -lclang -o bca BoostConAction.o
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseParmVarDecl(clang::ParmVarDecl*)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1600: undefined reference to `clang::ParmVarDecl::getDefaultArg()'
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseDeclContextHelper(clang::DeclContext*)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1049: undefined reference to `clang::DeclContext::decls_begin() const'
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1050: undefined reference to `clang::DeclContext::decls_end() const'
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:532: undefined reference to `clang::NestedNameSpecifier::getKind() const'
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:541: undefined reference to `clang::NestedNameSpecifierLoc::getTypeLoc() const'
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseNestedNameSpecifier(clang::NestedNameSpecifier*)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:508: undefined reference to `clang::NestedNameSpecifier::getKind() const'
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseObjCMessageExpr(clang::ObjCMessageExpr*)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1871: undefined reference to `clang::ObjCMessageExpr::children()'
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseUnaryExprOrTypeTraitExpr(clang::UnaryExprOrTypeTraitExpr*)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1790: undefined reference to `clang::UnaryExprOrTypeTraitExpr::children()'
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseClassTemplateSpecializationDecl(clang::ClassTemplateSpecializationDecl*)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1407: undefined reference to `clang::CXXRecordDecl::getTemplateSpecializationKind() const'
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseFunctionInstantiations(clang::FunctionTemplateDecl*)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1284: undefined reference to `clang::FunctionDecl::getTemplateSpecializationKind() const'
BoostConAction.o: In function `clang::RecursiveASTVisitor<(anonymous namespace)::BoostConASTConsumer>::TraverseClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl*)':
/workspace/build/include/clang/AST/RecursiveASTVisitor.h:1437: undefined reference to `clang::ClassTemplateSpecializationDecl::getSpecializedTemplate() const'
BoostConAction.o: In function `main':
....


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev