[cfe-dev] help needed in compiling tutorial example

Nobin Mathew nobin.mathew at gmail.com
Tue Jun 15 22:06:57 PDT 2010


Hi,

I am having a compilation issue with tutorial example, please give me
some directions.

hash#g++ `/home/nmathew/Desktop/llvm_work/llvm/Debug/bin/llvm-config
--ldflags` -lLLVMSupport -lLLVMSystem -lLLVMBitReader -lLLVMBitWriter
-lclangBasic -lclangLex -lclangDriver -lclangIndex -lclangFrontend
-lclangDriver -lclangSema -lclangAnalysis -lclangAST -lclangParse -o
tut01 tut01_pp.o

tut01_pp.o: In function
`clang::Diagnostic::setDiagnosticMapping(unsigned int,
clang::diag::Mapping)':
/home/nmathew/Desktop/llvm_work/llvm/tools/clang/include/clang/Basic/Diagnostic.h:364:
undefined reference to
`clang::Diagnostic::isBuiltinWarningOrExtension(unsigned int)'
tut01_pp.o: In function `SourceManager':
/home/nmathew/Desktop/llvm_work/llvm/tools/clang/include/clang/Basic/SourceManager.h:409:
undefined reference to `llvm::BumpPtrAllocator::DefaultSlabAllocator'
/home/nmathew/Desktop/llvm_work/llvm/tools/clang/include/clang/Basic/SourceManager.h:409:
undefined reference to
`llvm::BumpPtrAllocator::BumpPtrAllocator(unsigned int, unsigned int,
llvm::SlabAllocator&)'
/home/nmathew/Desktop/llvm_work/llvm/tools/clang/include/clang/Basic/SourceManager.h:410:
undefined reference to `clang::SourceManager::clearIDTables()'
tut01_pp.o: In function `PPContext':
/home/nmathew/Desktop/cppscope/PPContext.h:101: undefined reference to
`llvm::errs()'
/home/nmathew/Desktop/cppscope/PPContext.h:101: undefined reference to
`clang::TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream&,
clang::DiagnosticOptions const&, bool)'
/home/nmathew/Desktop/cppscope/PPContext.h:101: undefined reference to
`clang::Diagnostic::Diagnostic(clang::DiagnosticClient*)'
/home/nmathew/Desktop/cppscope/PPContext.h:101: undefined reference to
`clang::FileManager::FileManager()'
/home/nmathew/Desktop/cppscope/PPContext.h:101: undefined reference to
`clang::HeaderSearch::HeaderSearch(clang::FileManager&)'
/home/nmathew/Desktop/cppscope/PPContext.h:114: undefined reference to
`clang::TargetInfo::CreateTargetInfo(clang::Diagnostic&,
clang::TargetOptions&)'
/home/nmathew/Desktop/cppscope/PPContext.h:116: undefined reference to
`clang::Preprocessor::Preprocessor(clang::Diagnostic&,
clang::LangOptions const&, clang::TargetInfo const&,
clang::SourceManager&, clang::HeaderSearch&,
clang::IdentifierInfoLookup*, bool)'
tut01_pp.o: In function `~PPContext':
/home/nmathew/Desktop/cppscope/PPContext.h:123: undefined reference to
`clang::Preprocessor::~Preprocessor()'
/home/nmathew/Desktop/cppscope/PPContext.h:124: undefined reference to
`clang::HeaderSearch::~HeaderSearch()'
/home/nmathew/Desktop/cppscope/PPContext.h:124: undefined reference to
`clang::FileManager::~FileManager()'
/home/nmathew/Desktop/cppscope/PPContext.h:124: undefined reference to
`clang::SourceManager::~SourceManager()'
/home/nmathew/Desktop/cppscope/PPContext.h:124: undefined reference to
`clang::Diagnostic::~Diagnostic()'
collect2: ld returned 1 exit status

and

hash#/home/nmathew/Desktop/llvm_work/llvm/Debug/bin/llvm-config --ldflags
-L/home/nmathew/Desktop/llvm_work/llvm/Debug/lib  -lpthread -ldl -lm


Source code for the modified example is below.


#cat tu01_pp.cpp

#include "PPContext.h"

int main()
{
  PPContext context;
}



#cat PPContext.h

#ifndef PP_CONTEXT
#define PP_CONTEXT

#include <string>

#include "clang/Basic/Diagnostic.h"
#include "clang/Driver/Arg.h"
#include "clang/Driver/ArgList.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/CC1AsOptions.h"
#include "clang/Driver/OptTable.h"
#include "clang/Driver/Options.h"
#include "clang/Frontend/DiagnosticOptions.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"

#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/PCHReader.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Job.h"
#include "clang/Driver/Tool.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/System/Host.h"
#include "llvm/System/Path.h"

#include "llvm/ADT/OwningPtr.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/MC/MCParser/AsmParser.h"
#include "llvm/MC/MCCodeEmitter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Host.h"
#include "llvm/System/Path.h"
#include "llvm/System/Signals.h"
#include "llvm/Target/TargetAsmBackend.h"
#include "llvm/Target/TargetAsmParser.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetSelect.h"

#include "llvm/Config/config.h"

#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/FileManager.h"

#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"

#include "clang/Frontend/ASTConsumers.h"
#include "clang/Sema/ParseAST.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/System/Process.h"
#include "llvm/System/Program.h"

using namespace clang;
using namespace clang::driver;
using namespace llvm;

struct PPContext {

  // Takes ownership of client.
  PPContext(clang::DiagnosticClient* client = 0,
            const std::string& triple = LLVM_HOSTTRIPLE)
    : diagClient(client == 0?new clang::TextDiagnosticPrinter(errs(),
DiagnosticOptions()):client),
      diags(diagClient),
      sm(diags),
      headers(fm)
  {
    // Configure warnings to be similar to what command-line `clang` outputs
    // (see tut03).
    // XXX: move warning initialization to libDriver
    using namespace clang;
    diags.setDiagnosticMapping(diag::warn_integer_too_large,diag::MAP_IGNORE);
    TargetOptions TargetOpts;
    TargetOpts.ABI = "";
    TargetOpts.CXXABI = "itanium";
    TargetOpts.CPU = "";
    TargetOpts.Features.clear();
    TargetOpts.Triple = triple;
    target = clang::TargetInfo::CreateTargetInfo(diags, TargetOpts);

    pp = new clang::Preprocessor(diags, opts, *target, sm, headers);
  }

  ~PPContext()
  {
    delete diagClient;
    delete target;
    delete pp;
  }
	


  clang::DiagnosticClient* diagClient;
  clang::Diagnostic diags;
  clang::SourceManager sm;
  clang::LangOptions opts;
  clang::TargetInfo* target;
  clang::FileManager fm;
  clang::HeaderSearch headers;
  clang::Preprocessor *pp;
};

#endif

Thanks
Nobin



More information about the cfe-dev mailing list