title: link fails with clang / llvm using g++
body: <p>I'm trying to compile this .ccp file. I got it from <a href="https://github.com/loarabia/Clang-tutorial" rel="nofollow">https://github.com/loarabia/Clang-tutorial</a>.</p>
  
  <pre><code>// This code is licensed under the New BSD license.
  // See LICENSE.txt for more details.
  #include &lt;iostream&gt;
  
  #include "llvm/Support/raw_ostream.h"
  #include "llvm/Support/Host.h"
  #include "llvm/ADT/IntrusiveRefCntPtr.h"
  
  #include "clang/Frontend/DiagnosticOptions.h"
  #include "clang/Frontend/TextDiagnosticPrinter.h"
  
  #include "clang/Basic/LangOptions.h"
  #include "clang/Basic/FileSystemOptions.h"
  
  #include "clang/Basic/SourceManager.h"
  #include "clang/Lex/HeaderSearch.h"
  #include "clang/Basic/FileManager.h"
  
  #include "clang/Basic/TargetOptions.h"
  #include "clang/Basic/TargetInfo.h"
  
  #include "clang/Lex/Preprocessor.h"
  #include "clang/Frontend/CompilerInstance.h"
  
  
  int main()
  {
      clang::DiagnosticOptions diagnosticOptions;
      clang::TextDiagnosticPrinter *pTextDiagnosticPrinter =
          new clang::TextDiagnosticPrinter(
              llvm::outs(),
              diagnosticOptions);
      llvm::IntrusiveRefCntPtr&lt;clang::DiagnosticIDs&gt; pDiagIDs;
      //clang::DiagnosticIDs diagIDs;
  
      clang::DiagnosticsEngine *pDiagnosticsEngine =
          new clang::DiagnosticsEngine(pDiagIDs, pTextDiagnosticPrinter);
  
      clang::LangOptions languageOptions;
      clang::FileSystemOptions fileSystemOptions;
      clang::FileManager fileManager(fileSystemOptions);
      clang::SourceManager sourceManager(
          *pDiagnosticsEngine,
          fileManager);
      clang::HeaderSearch headerSearch(fileManager, *pDiagnosticsEngine);
  
      clang::TargetOptions targetOptions;
      targetOptions.Triple = llvm::sys::getDefaultTargetTriple();
  
      clang::TargetInfo *pTargetInfo = 
          clang::TargetInfo::CreateTargetInfo(
              *pDiagnosticsEngine,
              targetOptions);
      clang::CompilerInstance compInst;
  
      clang::Preprocessor preprocessor(
          *pDiagnosticsEngine,
          languageOptions,
          pTargetInfo,
          sourceManager,
          headerSearch,
          compInst);
  
      return 0;
  }
  </code></pre>
  
  <p>And I use g++ compile line like this:</p>
  
  <pre><code>  g++ tutorial1.cpp -g -fno-rtti `llvm-config --cxxflags --ldflags --libs` -lclangBasic
   -lclangLex -lclangDriver -lclangFrontend -lclangParse -lclangAST -lclangSema
   -lclangAnalysis  -I ../llvm/tools/clang/include/ 
  -I/Users/scher/Documents/Projects/task/C/last_clang/llvm/include 
  -I/Users/scher/Documents/Projects/task/C/last_clang/build/include  
  -I/Users/scher/Documents/Projects/task/C/last_clang/build/tools/clang/include
  </code></pre>
  
  <p>But it fails with the following report:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "clang::serialization::ModuleManager::lookup(llvm::StringRef)", referenced from:
        clang::ASTUnit::TranslateStoredDiagnostics(clang::ASTReader*, llvm::StringRef, clang::SourceManager&amp;, llvm::SmallVectorImpl&lt;clang::StoredDiagnostic&gt; const&amp;, llvm::SmallVectorImpl&lt;clang::StoredDiagnostic&gt;&amp;)in libclangFrontend.a(ASTUnit.o)
    "clang::ASTWriter::ASTWriter(llvm::BitstreamWriter&amp;)", referenced from:
        clang::ASTUnit::serialize(llvm::raw_ostream&amp;)      in libclangFrontend.a(ASTUnit.o)
    "clang::ASTWriter::WriteAST(clang::Sema&amp;, clang::MemorizeStatCalls*, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, clang::Module*, llvm::StringRef)", referenced from:
        clang::ASTUnit::serialize(llvm::raw_ostream&amp;)      in libclangFrontend.a(ASTUnit.o)
    "clang::ASTWriter::~ASTWriter()", referenced from:
        clang::ASTUnit::serialize(llvm::raw_ostream&amp;)      in libclangFrontend.a(ASTUnit.o)
    "clang::PCHGenerator::PCHGenerator(clang::Preprocessor const&amp;, llvm::StringRef, clang::Module*, llvm::StringRef, llvm::raw_ostream*)", referenced from:
        (anonymous namespace)::PrecompilePreambleConsumer::PrecompilePreambleConsumer(clang::ASTUnit&amp;, clang::Preprocessor const&amp;, llvm::StringRef, llvm::raw_ostream*)in libclangFrontend.a(ASTUnit.o)
    "clang::PCHGenerator::HandleTranslationUnit(clang::ASTContext&amp;)", referenced from:
        (anonymous namespace)::PrecompilePreambleConsumer::HandleTranslationUnit(clang::ASTContext&amp;)in libclangFrontend.a(ASTUnit.o)
    "clang::ASTWriter::getDeclID(clang::Decl const*)", referenced from:
        (anonymous namespace)::PrecompilePreambleConsumer::HandleTranslationUnit(clang::ASTContext&amp;)in libclangFrontend.a(ASTUnit.o)
    "clang::PCHGenerator::~PCHGenerator()", referenced from:
        (anonymous namespace)::PrecompilePreambleConsumer::~PrecompilePreambleConsumer()in libclangFrontend.a(ASTUnit.o)
    "vtable for clang::ASTReaderListener", referenced from:
        clang::ASTReaderListener::ASTReaderListener()in libclangFrontend.a(ASTUnit.o)
    "clang::ASTReaderListener::~ASTReaderListener()", referenced from:
        (anonymous namespace)::ASTInfoCollector::~ASTInfoCollector()in libclangFrontend.a(ASTUnit.o)
    "clang::PCHGenerator::GetASTMutationListener()", referenced from:
        vtable for (anonymous namespace)::PrecompilePreambleConsumerin libclangFrontend.a(ASTUnit.o)
    "clang::PCHGenerator::GetASTDeserializationListener()", referenced from:
        vtable for (anonymous namespace)::PrecompilePreambleConsumerin libclangFrontend.a(ASTUnit.o)
    "clang::serialization::ModuleManager::addInMemoryBuffer(llvm::StringRef, llvm::MemoryBuffer*)", referenced from:
        clang::ASTReader::addInMemoryBuffer(llvm::StringRef&amp;, llvm::MemoryBuffer*)     in libclangFrontend.a(ChainedIncludesSource.o)
    "clang::ASTReader::ASTReader(clang::Preprocessor&amp;, clang::ASTContext&amp;, llvm::StringRef, bool, bool)", referenced from:
        clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, bool, bool, clang::Preprocessor&amp;, clang::ASTContext&amp;, void*, bool)in libclangFrontend.a(CompilerInstance.o)
        clang::CompilerInstance::loadModule(clang::SourceLocation, llvm::ArrayRef&lt;std::pair&lt;clang::IdentifierInfo*, clang::SourceLocation&gt; &gt;, clang::Module::NameVisibilityKind, bool)in libclangFrontend.a(CompilerInstance.o)
        clang::ASTUnit::LoadFromASTFile(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, llvm::IntrusiveRefCntPtr&lt;clang::DiagnosticsEngine&gt;, clang::FileSystemOptions const&amp;, bool, std::pair&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, llvm::PointerUnion&lt;char const*, llvm::MemoryBuffer const*&gt; &gt;*, unsigned int, bool)in libclangFrontend.a(ASTUnit.o)
        createASTReader(clang::CompilerInstance&amp;, llvm::StringRef, llvm::SmallVector&lt;llvm::MemoryBuffer*, 4u&gt;&amp;, llvm::SmallVector&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, 4u&gt;&amp;, clang::ASTDeserializationListener*)in libclangFrontend.a(ChainedIncludesSource.o)
    "clang::ASTReader::setDeserializationListener(clang::ASTDeserializationListener*)", referenced from:
        clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, bool, bool, clang::Preprocessor&amp;, clang::ASTContext&amp;, void*, bool)in libclangFrontend.a(CompilerInstance.o)
        clang::CompilerInstance::loadModule(clang::SourceLocation, llvm::ArrayRef&lt;std::pair&lt;clang::IdentifierInfo*, clang::SourceLocation&gt; &gt;, clang::Module::NameVisibilityKind, bool)in libclangFrontend.a(CompilerInstance.o)
        createASTReader(clang::CompilerInstance&amp;, llvm::StringRef, llvm::SmallVector&lt;llvm::MemoryBuffer*, 4u&gt;&amp;, llvm::SmallVector&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, 4u&gt;&amp;, clang::ASTDeserializationListener*)in libclangFrontend.a(ChainedIncludesSource.o)
    "clang::ASTReader::ReadAST(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, clang::serialization::ModuleKind)", referenced from:
        clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, bool, bool, clang::Preprocessor&amp;, clang::ASTContext&amp;, void*, bool)in libclangFrontend.a(CompilerInstance.o)
        clang::CompilerInstance::loadModule(clang::SourceLocation, llvm::ArrayRef&lt;std::pair&lt;clang::IdentifierInfo*, clang::SourceLocation&gt; &gt;, clang::Module::NameVisibilityKind, bool)in libclangFrontend.a(CompilerInstance.o)
        clang::ASTUnit::LoadFromASTFile(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, llvm::IntrusiveRefCntPtr&lt;clang::DiagnosticsEngine&gt;, clang::FileSystemOptions const&amp;, bool, std::pair&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, llvm::PointerUnion&lt;char const*, llvm::MemoryBuffer const*&gt; &gt;*, unsigned int, bool)in libclangFrontend.a(ASTUnit.o)
        createASTReader(clang::CompilerInstance&amp;, llvm::StringRef, llvm::SmallVector&lt;llvm::MemoryBuffer*, 4u&gt;&amp;, llvm::SmallVector&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, 4u&gt;&amp;, clang::ASTDeserializationListener*)in libclangFrontend.a(ChainedIncludesSource.o)
    "clang::ASTReader::makeModuleVisible(clang::Module*, clang::Module::NameVisibilityKind)", referenced from:
        clang::CompilerInstance::loadModule(clang::SourceLocation, llvm::ArrayRef&lt;std::pair&lt;clang::IdentifierInfo*, clang::SourceLocation&gt; &gt;, clang::Module::NameVisibilityKind, bool)in libclangFrontend.a(CompilerInstance.o)
    "clang::ASTReader::getOriginalSourceFile(std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;, clang::FileManager&amp;, clang::DiagnosticsEngine&amp;)", referenced from:
        ParsePreprocessorArgs(clang::PreprocessorOptions&amp;, clang::driver::ArgList&amp;, clang::FileManager&amp;, clang::DiagnosticsEngine&amp;)in libclangFrontend.a(CompilerInvocation.o)
    "clang::ASTDeserializationListener::~ASTDeserializationListener()", referenced from:
        (anonymous namespace)::DelegatingDeserializationListener::~DelegatingDeserializationListener()in libclangFrontend.a(FrontendAction.o)
        clang::MultiplexASTDeserializationListener::~MultiplexASTDeserializationListener()in libclangFrontend.a(MultiplexConsumer.o)
    "vtable for clang::ASTDeserializationListener", referenced from:
        clang::ASTDeserializationListener::ASTDeserializationListener()in libclangFrontend.a(FrontendAction.o)
        clang::ASTDeserializationListener::ASTDeserializationListener()in libclangFrontend.a(MultiplexConsumer.o)
    "clang::PCHGenerator::PCHGenerator(clang::Preprocessor const&amp;, llvm::StringRef, clang::Module*, llvm::StringRef, llvm::raw_ostream*)", referenced from:
        clang::GeneratePCHAction::CreateASTConsumer(clang::CompilerInstance&amp;, llvm::StringRef)    in libclangFrontend.a(FrontendActions.o)
        clang::GenerateModuleAction::CreateASTConsumer(clang::CompilerInstance&amp;, llvm::StringRef)    in libclangFrontend.a(FrontendActions.o)
        clang::ChainedIncludesSource::create(clang::CompilerInstance&amp;)   in libclangFrontend.a(ChainedIncludesSource.o)
  ld: symbol(s) not found for architecture x86_64
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>I'd like to add that it occurs, when you add this <code>clang::CompilerInstance compInst;</code> line of code. Without this line it compiles normally.</p>
  
  <p>Also I use clang/llvm 3.0, It was built using this tutorial <a href="http://clang.llvm.org/get_started.html" rel="nofollow">http://clang.llvm.org/get_started.html</a></p>
  
  <p>Any suggestions why it could fails?</p>