gpt4 book ai didi

c++ - 如何在 STL 中使用 libclang?

转载 作者:可可西里 更新时间:2023-11-01 09:29:03 24 4
gpt4 key购买 nike

我正在尝试使用 libclang 解析一个库,但我遇到了一个可能非常简单的问题:如何使用 STL 配置它?目前,它无法解析翻译单元,因为找不到 <string> .

这是我尝试过的:

char *args[] = {"-x", "c++", "-Ic:/my/library/includes", "-IG:/Prog/libcxx-3.4/include"};
clang_parseTranslationUnit(index, "c:/my/library/test.cpp", args, 4, 0, 0, 0);

我在 Windows 上,使用从 llvm.org 下载的预编译 clang 二进制文件,我尝试了各种 STL 实现:

  • Visual Studio
  • 铭文
  • libCXX

在每种情况下,我都以未知类型结束。

例如,使用 mingw,我收到以下错误消息:

/mingw/include\wchar.h:221:71: error: unknown type name '_locale_t'
/mingw/include\wchar.h:223:81: error: unknown type name '_locale_t'
/mingw/include\stdlib.h:173:65: error: unknown type name '_locale_t'
/mingw/include\stdlib.h:175:75: error: unknown type name '_locale_t'
/mingw/include\io.h:301:14: error: unknown type name 'off64_t'
/mingw/include\io.h:301:36: error: C++ requires a type specifier for all declarations
/mingw/include\io.h:302:14: error: unknown type name 'off64_t'
/mingw/include\io.h:302:39: error: unknown type name 'off64_t'
/mingw/include\unistd.h:65:20: error: unknown type name 'off_t'

我找到的关于这个主题的罕见教程没有谈论这个主题......

最佳答案

由于 libclang 是预编译的,它不知道编译器使用的标准库的确切路径。在调用 clang_parseTranslationUnit 时,您必须使用参数列表中的 -I 开关告诉它标准包含路径。

这是我用来在 Linux 上查找 gcc 包含路径的命令。您应该能够在您的 windows 环境中将其适应 MinGW:

$ echo "" | g++ -v -x c++ -E -
...
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.8
/usr/include/x86_64-linux-gnu/c++/4.8
/usr/include/c++/4.8/backward
/usr/lib/gcc/x86_64-linux-gnu/4.8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
...

关于c++ - 如何在 STL 中使用 libclang?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22480534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com