Hi,<br>when i am trying to compile given source it gives linker error :<br><br><b>tutorial4.o:(.rodata._ZTIN5clang13MyASTConsumerE[typeinfo for clang::MyASTConsumer]+0x10): undefined reference to `typeinfo for clang::ASTConsumer'<br>

collect2: ld returned 1 exit status<br>make: *** [tutorial4] Error 1<br></b><br clear="all"><br>Source code is: all necessary header files are included and there is no syntax error in this source code, required libraries are also specified in make file.<br>

----------------------<br><br><i>class MyASTConsumer : public clang::ASTConsumer<br>{<br>public:<br>    MyASTConsumer() : clang::ASTConsumer() { }<br>    virtual ~MyASTConsumer() { }<br><br>    virtual void HandleTopLevelDecl( clang::DeclGroupRef d)<br>

    {<br>        static int count = 0;<br>        clang::DeclGroupRef::iterator it;<br>        for( it = d.begin(); it != d.end(); it++)<br>        {<br>            count++;<br>            clang::VarDecl *vd = dyn_cast<clang::VarDecl>(*it);<br>

            if(!vd)<br>            {<br>                continue;<br>            }<br>            std::cout << vd << std::endl;<br>            if( vd->isFileVarDecl() && vd->hasExternalStorage() )<br>

            {<br>                std::cerr << "Read top-level variable decl: '";<br>                std::cerr << vd->getDeclName().getAsString() ;<br>                std::cerr << std::endl;<br>

            }<br>        }<br>    }<br>};<br><br><br>int main()<br>{<br>    clang::DiagnosticOptions diagnosticOptions;<br>    clang::TextDiagnosticPrinter *pTextDiagnosticPrinter =<br>        new clang::TextDiagnosticPrinter(llvm::outs(),diagnosticOptions);<br>

    llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> pDiagIDs;<br>    clang::Diagnostic diagnostic(pDiagIDs, pTextDiagnosticPrinter);<br><br>    clang::LangOptions languageOptions;<br>    clang::FileSystemOptions fileSystemOptions;<br>

    clang::FileManager fileManager(fileSystemOptions);<br><br>    clang::SourceManager sourceManager( diagnostic, fileManager);<br>    clang::HeaderSearch headerSearch(fileManager);<br><br>    clang::HeaderSearchOptions headerSearchOptions;<br>

    <br>    headerSearchOptions.AddPath("/usr/include/linux",    clang::frontend::Angled,<br>            false,    false,    false);<br>    headerSearchOptions.AddPath("/usr/include/c++/4.4/tr1",    clang::frontend::Angled,<br>

            false,    false,    false);<br>    headerSearchOptions.AddPath("/usr/include/c++/4.4",clang::frontend::Angled,<br>            false,false,    false);<br>    <br><br>    clang::TargetOptions targetOptions;<br>

    targetOptions.Triple = llvm::sys::getHostTriple();<br><br>    clang::TargetInfo *pTargetInfo = <br>        clang::TargetInfo::CreateTargetInfo(diagnostic,targetOptions);<br><br>    clang::ApplyHeaderSearchOptions(headerSearch,headerSearchOptions,<br>

        languageOptions,pTargetInfo->getTriple());<br><br>    clang::Preprocessor preprocessor(diagnostic,    languageOptions,<br>        *pTargetInfo,sourceManager,headerSearch);<br><br>    clang::PreprocessorOptions preprocessorOptions;<br>

    clang::FrontendOptions frontendOptions;<br>    clang::InitializePreprocessor(preprocessor,preprocessorOptions,<br>        headerSearchOptions,frontendOptions);<br>        <br>    const clang::FileEntry *pFile = fileManager.getFile( "test.c");<br>

    sourceManager.createMainFileID(pFile);<br>    preprocessor.EnterMainSourceFile();<br><br>    const clang::TargetInfo &targetInfo = *pTargetInfo;<br><br>    clang::IdentifierTable identifierTable(languageOptions);<br>

    clang::SelectorTable selectorTable;<br><br>    clang::Builtin::Context builtinContext(targetInfo);<br>    clang::ASTContext astContext( languageOptions, sourceManager, targetInfo, identifierTable,<br>        selectorTable, builtinContext,   0 /* size_reserve*/);<br>

    clang::MyASTConsumer astConsumer;<br><br>    clang::Sema sema(preprocessor, astContext,  astConsumer);<br><br>   <br>     pTextDiagnosticPrinter->BeginSourceFile(languageOptions, &preprocessor);<br>    clang::ParseAST(preprocessor, &astConsumer, astContext); <br>

    pTextDiagnosticPrinter->EndSourceFile();<br>    <br><br>    return 0;<br>}</i><br> <br><b style="color: rgb(0, 0, 153);">can anybody tell me what is wrong with this.<br><br>___________________________________________________________________________</b><br>

<span style="color: rgb(0, 0, 153);">-----------------------------------------------------------------------------------------------------------------------------</span><br><b>Jignesh Vasoya<br>CSE - IIT MADRAS<br>9962248684</b><br>

<br>