http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
首先,您需要使用CMake为LLVM生成Makefiles。您需要创建一个构建目录并从中运行CMake:
$ mkdir your/build/directory $ cd your/build/directory $ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON path/to/llvm/sources
clang提供了一个curses接口为懒人们配置CMake变量。
-DCMAKE_C_COMPILER=/path/to/clang -DCMAKE_CXX_COMPILER=/path/to/clang++ccmake
结果,新compile_commands.json文件应该出现在当前目录中。您应该将其链接到LLVM源代码树,以便Clang Tooling能够使用它:
$ ln -s $PWD/compile_commands.json path/to/llvm/source/ 现在您已准备好使用make构建和测试LLVM: $ make check-all
例子:
$ clang-check tools / clang / tools / clang-check / ClangCheck.cpp -ast-dump -ast-dump-filter ActionFactory :: newASTConsumer 处理:tools / clang / tools / clang-check / ClangCheck.cpp。 Dumping :: ActionFactory :: newASTConsumer: clang :: ASTConsumer * newASTConsumer()(CompoundStmt 0x44da290 </home/alexfh/local/llvm/tools/clang/tools/clang-check/ClangCheck.cpp:64:40,line:72 :3> (IfStmt 0x44d97c8 <line:65:5,line:66:45> <<< NULL >>> (ImplicitCastExpr 0x44d96d0 <line:65:9>'_Bool':'_ Bool'<UserDefinedConversion> ... ... $ clang-check工具/ clang / tools / clang-check / ClangCheck.cpp -ast-print -ast-dump-filter ActionFactory :: newASTConsumer 处理: 打印<anonymous namespace> :: ActionFactory :: newASTConsumer: clang :: ASTConsumer * newASTConsumer(){ if(this-> ASTList.operator _Bool()) return clang :: CreateASTDeclNodeLister(); if(this-> ASTDump.operator _Bool()) 返回clang :: CreateASTDumper(nullptr / *转储到stdout。* /, this-> ASTDumpFilter); if(this-> ASTPrint.operator _Bool()) 返回clang :: CreateASTPrinter(&llvm :: outs(),this-> ASTDumpFilter); return new clang :: ASTConsumer(); }