我正在使用 libtooling 构建一个独立的工具。我有一个 FrontendAction
的基本样板代码, Consumer
和一个 Visitor
.访客只访问ClassTemplateSpecializationDecl
我只是保存一些信息。一切正常,但如果我 #include <string>
在我正在解析的文件中出现错误:'stddef.h' file not found
.
我以为编译器找不到一些系统头文件,但我正在解析的输入文件使用 clang++ 命令编译时没有任何错误。
最佳答案
对于基于libTooling
的工具来说,这是一个非常典型的错误:https://clang.llvm.org/docs/FAQ.html#id3
Some header files (stddef.h, stdarg.h, and others) are shipped with Clang — these are called builtin includes. Clang searches for them in a directory relative to the location of the clang binary. If you moved the clang binary, you need to move the builtin headers, too.
如果您使用 CMake,您可以添加以下代码来安装 Clang 的 header :
set(CLANG_BUILTIN_HEADERS_DIR "${LLVM_LIBRARY_DIR}/clang")
install(
DIRECTORY ${CLANG_BUILTIN_HEADERS_DIR}
DESTINATION lib
FILES_MATCHING PATTERN "*.h"
)
关于c++ - 使用 RecursiveASTVisitor 解析系统 header 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55315394/