如何在STL中使用libclang? [英] How to use libclang with STL?
问题描述
我正在尝试使用libclang解析库,但我遇到了一个非常简单的问题:如何使用STL对其进行配置?
目前,它无法解析翻译单元,因为找不到<string>
.
I'm trying to parse a library using libclang, and I'm stuck with what could be a very simple issue: how to configure it with STL?
At the moment, it fails to parse a translation unit because it can't find <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实现:
I'm on windows, with the precompiled clang binaries downloaded from llvm.org, and I tried with various STL implementations :
- Visual Studio
- MingW
- libCXX
在每种情况下,我最终都有未知的类型.
In each case, I ended up with unknown types.
例如,对于mingw,我收到以下错误消息:
For example, with mingw, I've got the following error messages :
/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'
我发现的有关该主题的罕见教程都没有谈论这个主题...
The rare tutorials I've found about this subject don't talk about this subject...
推荐答案
由于libclang已预编译,因此它不知道编译器使用的标准库的确切路径.调用clang_parseTranslationUnit
时,必须使用参数列表中的-I
开关告诉它标准的包含路径.
Since libclang was precompiled, it doesn't know about the exact paths of the standard libraries used by your compilers. You'll have to tell it about the standard include path using -I
switches in your arguments list, when calling clang_parseTranslationUnit
.
这是我用来查找Linux上gcc
包含路径的命令.您应该能够在Windows环境中使其适应MinGW:
Here is the command I use to find about the inclusion paths for gcc
on Linux. You should be able to adapt it to MinGW in your windows environment:
$ 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.
...
这篇关于如何在STL中使用libclang?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!