clang没有识别' ptrdiff_t',' size_t',' wchar_t'在解析AST时

时间:2014-06-25 11:17:01

标签: c++ clang abstract-syntax-tree

对于以下链接中提出的问题, clang getting include files while parsing AST

我使用了'解析示例文件'对于我的输入文件,我的系统特定的标题路径,但我得到错误的' 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生成与系统头文件相关的诊断信息。我无法找到任何办法,因为我认为没有任何直接的方法可以做到这一点。

1 个答案:

答案 0 :(得分:1)

虽然Clang和GCC之间的互操作在某种程度上是可能的,但是一些标准库头部依赖于编译器。实际上,stddef.h和stdarg.h是produced along with Clang when you build it。它们被视为“built-in includes”。如果你没有它们,你很可能无法正常工作。

好消息是,如果你有Clang驱动程序,你可能也有标题。正如他们在网站上提到的那样,Clang在$(path/to/tool)/../lib/clang/3.3/include中查找这些标题。