在c++中使用CLang

Working with CLang in c++

本文关键字:CLang c++      更新时间:2023-10-16

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

#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"

当我使用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.

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

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

我会从下载页面获取一个预构建的Clang+LLVM,并根据它进行编译/链接。

sudo apt-get-install libclang-3.8-dev#或libclang-39-dev