[cfe-dev] ASTContext: how to get an object or pointer of ASTContext

Douglas Gregor dgregor at apple.com
Tue May 18 18:22:46 PDT 2010


On May 18, 2010, at 6:19 PM, Jiandong Wang wrote:

> 
> 
> On Tue, May 18, 2010 at 10:11 PM, Douglas Gregor <dgregor at apple.com> wrote:
> 
> On May 18, 2010, at 6:09 AM, Jiandong Wang wrote:
> 
>> Hi all:
>>     now I am trying to run my own ASTConsumer against AST, but not quite sure how to do it, especially how to get an object or pointer of ASTContext. BTW, ASTContext is required by ParseAST.  
>> here is my code snippet:
>> 
> 
> You can just create an ASTContext on the stack, passing in the various other pieces (lang options, source manager, target info, etc.) when you construct it.
>  
>  Thank you. I finally compiled it through.my command:
>        g++ `llvm-config --cxxflags --ldflags` -fno-rtti -c Myfile.cpp -o Myfile.o
> but when I generated the executable, unexpected errors occured. my command:
>        g++ `llvm-config --cxxflasg --ldflags --libs core` -o Myfile Myfile.o 
> 
> errors like this:
> undefined reference to 'llvm::errs()'
> undefined reference to 'clang::Diagnostic::Diagnostic(clang::DiagnosticClient*)'
> undefined reference to 'clang::FileManager::FileManager()'
> 
> missing something? 

You need to link against the Clang libraries. -lClangBasic -lClang -lClangAST and so on.

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100518/b11838ff/attachment.html>


More information about the cfe-dev mailing list