help needed in compiling tutorial example

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

help needed in compiling tutorial example

Nobin Mathew
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
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: help needed in compiling tutorial example

Sebastian Redl

On Wed, 16 Jun 2010 10:36:57 +0530, Nobin Mathew <[hidden email]>
wrote:

> 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

Where is this tutorial from? The problem here is the command line.
Libraries in *nix systems must be listed in reverse dependency order, i.e.
first a library, then the libraries it depends on. So the llvm-config
invocation must be last, all explicit llvm library directives should be
removed in favor of appropriate llvm-config arguments (it ensures correct
ordering), and the Clang libraries must be correctly ordered and come
before the LLVM stuff.

An order that ought to work for Clang is Driver, Frontend, Analysis,
Index, Sema, AST, Parse, Lex, Basic, although recent trunk changes have
changed the dependencies between Frontend and some other modules.

We *really* need a clang-config tool or teach llvm-config to deal with
Clang libraries.

Sebastian

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: help needed in compiling tutorial example

Nobin Mathew
Thanks a lot,

This worked for me

g++ tut01_pp.cpp -g -fno-rtti -lclangDriver -lclangAnalysis
-lclangFrontend -lclangSema -lclangAST -lclangParse -lclangLex
-lclangBasic -I/home/nmathew/Desktop/llvm_work/llvm/tools/clang/include/
`/home/nmathew/Desktop/llvm_work/llvm/Debug/bin/llvm-config --cxxflags
--ldflags --libs`

But this gives errors

g++ -g -fno-rtti -lclangDriver -lclangAnalysis -lclangFrontend
-lclangSema -lclangAST -lclangParse -lclangLex -lclangBasic
-I/home/nmathew/Desktop/llvm_work/llvm/tools/clang/include/
`/home/nmathew/Desktop/llvm_work/llvm/Debug/bin/llvm-config --cxxflags
--ldflags --libs` tut01_pp.cpp

/tmp/ccTgoghe.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()'
/tmp/ccTgoghe.o: In function `PPContext':
/home/nmathew/Desktop/cppscope/PPContext.h:97: undefined reference to
`llvm::errs()'
/home/nmathew/Desktop/cppscope/PPContext.h:97: undefined reference to
`clang::TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream&,
clang::DiagnosticOptions const&, bool)'
/home/nmathew/Desktop/cppscope/PPContext.h:97: undefined reference to
`clang::Diagnostic::Diagnostic(clang::DiagnosticClient*)'
/home/nmathew/Desktop/cppscope/PPContext.h:97: undefined reference to
`clang::FileManager::FileManager()'
/home/nmathew/Desktop/cppscope/PPContext.h:97: undefined reference to
`clang::HeaderSearch::HeaderSearch(clang::FileManager&)'
/home/nmathew/Desktop/cppscope/PPContext.h:110: undefined reference to
`clang::TargetInfo::CreateTargetInfo(clang::Diagnostic&,
clang::TargetOptions&)'
/home/nmathew/Desktop/cppscope/PPContext.h:112: undefined reference to
`clang::Preprocessor::Preprocessor(clang::Diagnostic&,
clang::LangOptions const&, clang::TargetInfo const&,
clang::SourceManager&, clang::HeaderSearch&,
clang::IdentifierInfoLookup*, bool)'
/tmp/ccTgoghe.o: In function `~PPContext':
/home/nmathew/Desktop/cppscope/PPContext.h:119: undefined reference to
`clang::Preprocessor::~Preprocessor()'
/home/nmathew/Desktop/cppscope/PPContext.h:120: undefined reference to
`clang::HeaderSearch::~HeaderSearch()'
/home/nmathew/Desktop/cppscope/PPContext.h:120: undefined reference to
`clang::FileManager::~FileManager()'
/home/nmathew/Desktop/cppscope/PPContext.h:120: undefined reference to
`clang::SourceManager::~SourceManager()'
/home/nmathew/Desktop/cppscope/PPContext.h:120: undefined reference to
`clang::Diagnostic::~Diagnostic()'
collect2: ld returned 1 exit status

what is the difference here.

Thanks
Nobin

On Wed, Jun 16, 2010 at 2:02 PM, Sebastian Redl
<[hidden email]> wrote:

>
> On Wed, 16 Jun 2010 10:36:57 +0530, Nobin Mathew <[hidden email]>
> wrote:
>> 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
>
> Where is this tutorial from? The problem here is the command line.
> Libraries in *nix systems must be listed in reverse dependency order, i.e.
> first a library, then the libraries it depends on. So the llvm-config
> invocation must be last, all explicit llvm library directives should be
> removed in favor of appropriate llvm-config arguments (it ensures correct
> ordering), and the Clang libraries must be correctly ordered and come
> before the LLVM stuff.
>
> An order that ought to work for Clang is Driver, Frontend, Analysis,
> Index, Sema, AST, Parse, Lex, Basic, although recent trunk changes have
> changed the dependencies between Frontend and some other modules.
>
> We *really* need a clang-config tool or teach llvm-config to deal with
> Clang libraries.
>
> Sebastian
>
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev