对于在下面的链接中提出的问题,在解析AST时获得包含文件的clang
我使用“解析示例文件”作为输入文件的特定头路径,但是没有定义'ptrdiff_t‘、'size_t’、'wchar_t‘类型的错误。
我正在使用下面的标题路径:
/usr/include /usr/include/bits /usr/include/linux /usr/include/c++/4.1.2 /usr/include/c++/4.1.2/bits /usr/include/c++/4.1.2/tr1 /usr/include/c++/4.1.2/i386-redhat-linux/bits /usr/include/c++/4.1.2/i386-redhat-linux /usr/include/c++/4.1.2/i386-redhat-linux/tr1
此外,我还添加了以下内容,用于指定输入为c++。在LangOptions.h中,这些变量默认设置为0。
languageOptions.CPlusPlus = 1;//// C++ Support
languageOptions.Bool = 1; //// 'bool', 'true', 'false' keywords.
languageOptions.CXXOperatorNames =1;//// Treat C++ operator names as keywords
我得到的错误列在下面。任何解决这一问题的帮助都是非常感谢的。
In file included from /home/p/expl1.cpp:12:
In file included from /usr/include/c++/4.1.2/string:46:
In file included from /usr/include/c++/4.1.2/bits/char_traits.h:45:
In file included from /usr/include/c++/4.1.2/cstring:50:
/usr/include/c++/4.1.2/cstddef:54:11: error: no member named 'ptrdiff_t' in the global namespace
using ::ptrdiff_t;
~~^
In file included from /usr/include/c++/4.1.2/string:46:
In file included from /usr/include/c++/4.1.2/bits/char_traits.h:45:
In file included from /usr/include/c++/4.1.2/cstring:52:
/usr/include/string.h:39:40: error: unknown type name 'size_t'
__const void *__restrict __src, size_t __n)
^
/usr/include/string.h:43:58: error: unknown type name 'size_t'
extern void *memmove (void *__dest, __const void *__src, size_t __n)
^
/usr/include/string.h:52:18: error: unknown type name 'size_t'
int __c, size_t __n)
^
/usr/include/string.h:59:42: error: unknown type name 'size_t'
/usr/include/c++/4.1.2/bits/stringfwd.h:63:33: error: use of undeclared identifier 'wchar_t'
template<> struct char_traits<wchar_t>;
我注意到这些应该在stddef.h中定义,但是我在/usr/include/linux/stddef.h中的stddef.h
#ifndef _LINUX_STDDEF_H
#define _LINUX_STDDEF_H
#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
谢谢你提前提供帮助。
是否有可能禁用clang生成与系统头文件相关的诊断信息?我找不到任何方法来做这件事,因为我不认为有任何直接的方法来做这件事。
发布于 2014-06-26 06:43:46
虽然Clang和GCC之间的互操作在某种程度上是可能的,但是一些标准的库头非常依赖于编译器。实际上,stddef.h和stdarg.h是当你建造它的时候和Clang一起制作的。他们被认为是"内建包括“。如果你没有它们,你很有可能无法使它正常工作。
好消息是,如果您有Clang驱动程序,您可能也有标题。正如他们在网站上提到的那样,Clang在$(path/to/tool)/../lib/clang/3.3/include
中查找这些标题。
https://stackoverflow.com/questions/24407193
复制相似问题