[cfe-dev] When Parsing AST,include file not found

%绝对冰儿 511736596 at qq.com
Mon Apr 27 17:39:46 PDT 2015


Hi:
   I'm using clang3.6, first time I use compilerInstance+ParseAST to operate AST.When the sourcefile have an fatal error:'stdio.h' file not found. Second time I use compilerInvocation+ASTUnit to operate AST.It have the same problem.
the source of compilerInvocation+ASTUnit( parse the ast of c)
  int main(int argc, char** argv)
{
    shared_ptr<ASTUnit> AST;
        clang::DiagnosticOptions diagOpts;
        llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags = clang::CompilerInstance::createDiagnostics(&diagOpts, 0, 0);
        clang::LangOptions lopt;
        vector<const char*> argvec;
        argvec.push_back("clang");
        argvec.push_back("-fsyntax-only");
        argvec.push_back(argv[1]);    //it's the filename
        ArrayRef<const char *> args(argvec);
        CompilerInvocation *ci = new clang::CompilerInvocation();
        CompilerInvocation::CreateFromArgs(*ci,&argvec[0],&argvec[0]+1,*diags);
        ci->setLangDefaults(lopt,InputKind::IK_C);
        llvm::outs()<<"createinvocationfromcommandline"<<"\n";
        ci->getPreprocessorOutputOpts().ShowComments = 1;
        ci->getPreprocessorOutputOpts().ShowLineMarkers = 1;
        llvm::outs()<<"preprocessor init "<<"\n";
        AST = clang::ASTUnit::LoadFromCompilerInvocation(ci, diags);
        llvm::outs()<<"createAST"<<"\n";
        MyASTVisitor myvis;
        myvis.TraverseDecl(AST->getASTContext().getTranslationUnitDecl());
}
what i miss? I don't know how to correctly create object of CompilerInvocation,I think it's because i don't correctly new the compilerinvocation.
Thank you so much!

by YingLi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150428/9e300f3b/attachment.html>


More information about the cfe-dev mailing list