[cfe-dev] Howto build clang tools using cmake

Anwar Ludin anwar.ludin at gmail.com
Mon Jul 21 02:12:15 PDT 2014


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


   






More information about the cfe-dev mailing list