在 C++ 中使用 CLang

Ahm*_*boh 2 c++ llvm clang

我的程序中有一个与包含文件相关的编译错误,在我的程序中我包含了以下文件:

#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
Run Code Online (Sandbox Code Playgroud)

使用 g++ 编译程序时得到的错误消息是:

In file included from /usr/include/clang/AST/APValue.h:17:0,
                 from /usr/include/clang/AST/Decl.h:17,
                 from /usr/include/clang/AST/RecursiveASTVisitor.h:17,
                 from FindClassDecls.cpp:2:
/usr/include/clang/Basic/LLVM.h:20:34: fatal error: llvm/Support/Casting.h: No such file or directory
compilation terminated.
Run Code Online (Sandbox Code Playgroud)

我不知道如何解决这个问题,而且我也不确定我是否正确安装了 CLang 库,所以请您告诉我如何解决问题或如何在 linux (Ubuntu) 上正确安装它。

Eli*_*sky 5

您似乎安装了 Clang 标头,但没有安装 LLVM 标头(Clang 依赖于此)。编译代码时,需要传递 LLVM 头文件的路径-I像往常一样给你的编译器。

我会从下载页面获取一个预先构建的 Clang+LLVM并对其进行编译/链接。