[cfe-dev] Howto build clang tools using cmake
Anwar Ludin
anwar.ludin at gmail.com
Mon Jul 21 09:19:19 PDT 2014
Hi Nikola,
Thanks for the pointer. Moved the sources to ~/llvm/tools/clang/tools/extra/mytool and updated the CMakeLists.txt to reflect the link you provided, but I am getting the exact same build errors.
Are the docs in synch with the current Clang API (3.5)? Am I missing a library?
Content of my CMakeLists.txt:
set(LLVM_LINK_COMPONENTS support)
set(LLVM_USED_LIBS clangTooling clangBasic clangAST)
add_clang_executable(find-class-decls FindClassDecls.cpp)
target_link_libraries(find-class-decls
clangTooling
clangBasic
clangASTMatchers
)
Compiler errors:
[100%] Building CXX object tools/clang/tools/extra/mytool/CMakeFiles/find-class-decls.dir/FindClassDecls.cpp.o
/Users/aludin/clang-llvm/llvm/tools/clang/tools/extra/mytool/FindClassDecls.cpp:17:43: error: member access into incomplete
type 'clang::ASTContext'
FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getLocStart());
^
/Users/aludin/clang-llvm/llvm/tools/clang/include/clang/AST/ASTConsumer.h:20:9: note: forward declaration of
'clang::ASTContext'
class ASTContext;
^
/Users/aludin/clang-llvm/llvm/tools/clang/tools/extra/mytool/FindClassDecls.cpp:36:33: error: member access into incomplete
type 'clang::ASTContext'
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
^
/Users/aludin/clang-llvm/llvm/tools/clang/include/clang/AST/ASTConsumer.h:20:9: note: forward declaration of
'clang::ASTContext'
class ASTContext;
^
/Users/aludin/clang-llvm/llvm/tools/clang/tools/extra/mytool/FindClassDecls.cpp:44:31: error: virtual function
'CreateASTConsumer' has a different return type ('clang::ASTConsumer *') than the function it overrides (which has
return type 'std::unique_ptr<ASTConsumer>')
virtual clang::ASTConsumer *CreateASTConsumer(
^
/Users/aludin/clang-llvm/llvm/tools/clang/include/clang/Frontend/FrontendAction.h:64:40: note: overridden virtual function is
here
virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
Thanks!
Anwar
On 21 Jul 2014, at 12:08, Nikola Smiljanic <popizdeh at gmail.com> wrote:
> Have you read this http://clang.llvm.org/docs/LibASTMatchersTutorial.html#step-1-create-a-clangtool
>
>
> On Mon, Jul 21, 2014 at 7:12 PM, Anwar Ludin <anwar.ludin at gmail.com> wrote:
> Hello,
>
> Sorry if this question has already been asked. I am trying to compile the "How to write RecursiveASTVisitor based ASTFrontedActions" tutorial located here http://clang.llvm.org/docs/RAVFrontendAction.html by using CMake.
>
> In order to do this, I created a new "mytool" directory in the clang source tree containing the source code provided in the tutorial:
>
> ~/llvm/tools/clang/tools/mytool
>
> The directory contains the CMakeLists.txt and FindClassDecls.cpp provided in the tutorial.
>
> I have also updated the CMakeLists.txt file located at ~/llvm/tools/clang/tools/ so that the mytool directory is included in the CMake build process.
>
> However when I try to build the tool, I get the following errors (I suspect the clangTooling library is not found).
>
> [ 98%] Building CXX object tools/clang/tools/mytool/CMakeFiles/find-class-decls.dir/FindClassDecls.cpp.o
> /Users/aludin/clang-llvm/llvm/tools/clang/tools/mytool/FindClassDecls.cpp:17:43: error: member access into incomplete type
> 'clang::ASTContext'
> FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getLocStart());
> ^
> /Users/aludin/clang-llvm/llvm/tools/clang/include/clang/AST/ASTConsumer.h:20:9: note: forward declaration of
> 'clang::ASTContext'
> class ASTContext;
> ^
> /Users/aludin/clang-llvm/llvm/tools/clang/tools/mytool/FindClassDecls.cpp:36:33: error: member access into incomplete type
> 'clang::ASTContext'
> Visitor.TraverseDecl(Context.getTranslationUnitDecl());
> ^
> /Users/aludin/clang-llvm/llvm/tools/clang/include/clang/AST/ASTConsumer.h:20:9: note: forward declaration of
> 'clang::ASTContext'
> class ASTContext;
> ^
> /Users/aludin/clang-llvm/llvm/tools/clang/tools/mytool/FindClassDecls.cpp:44:31: error: virtual function 'CreateASTConsumer'
> has a different return type ('clang::ASTConsumer *') than the function it overrides (which has return type
> 'std::unique_ptr<ASTConsumer>')
> virtual clang::ASTConsumer *CreateASTConsumer(
> ^
> /Users/aludin/clang-llvm/llvm/tools/clang/include/clang/Frontend/FrontendAction.h:64:40: note: overridden virtual function is
> here
> virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
> ^
> 3 errors generated.
> make[2]: *** [tools/clang/tools/mytool/CMakeFiles/find-class-decls.dir/FindClassDecls.cpp.o] Error 1
> make[1]: *** [tools/clang/tools/mytool/CMakeFiles/find-class-decls.dir/all] Error 2
> make: *** [all] Error 2
>
> Any help on how to build this would be greatly appreciated.
>
> Thanks!
>
> Anwar
>
>
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140721/628623db/attachment.html>
More information about the cfe-dev
mailing list