我最近在Windows上做过这个.
从这里下载clang和llvm源代码.
安装cmake和Python(与文档相反,你只需要Python来构建clang;至少,如果找不到Python运行时,cmake会放弃).
您还需要VS2008或VS2010.
有一点不完全明显的是所需的目录结构:
projectRoot
build <- intermediate build files and DLLs, etc. will go here
llvm <- contents of llvm-3.0.src from llvm-3.0.tar go here
tools
clang <- contents of clang-3.0.src from clang-3.0.tar go here
Run Code Online (Sandbox Code Playgroud)
并按照步骤4以后的Windows构建说明进行操作.不要试图使用cmake GUI,这是一个恐怖; 只需使用构建说明中给出的命令.
一旦构建完成(需要一段时间),您将拥有:
projectRoot
build
bin
Release <- libclang.dll will be here
lib
Release <- libclang.lib will be here
llvm
tools
clang
include
clang-c <- Index.h is here
Run Code Online (Sandbox Code Playgroud)
Index.h定义了API来访问有关源代码的信息; 它包含了很多关于API的文档.
要开始使用clang,您需要以下内容:
CXIndex index = clang_createIndex(1, 1);
// Support Microsoft extensions
char *args[] = {"-fms-extensions"};
CXTranslationUnit tu = clang_parseTranslationUnit(index, "mySource.c", args, ARRAY_SIZE(args), 0, 0, 0);
if (tu)
{
CXCursor cursor = clang_getTranslationUnitCursor(tu);
// Use the cursor functions to navigate through the AST
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2463 次 |
最近记录: |