clang在解析AST时不标识“ptrdiff_t”,“size_t”,“wchar_t” [英] clang not identifying 'ptrdiff_t', 'size_t', 'wchar_t' while parsing AST

查看:1781
本文介绍了clang在解析AST时不标识“ptrdiff_t”,“size_t”,“wchar_t”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下链接中提出的问题,
clang在解析AST时获取包含文件

For the question raised in the below link, clang getting include files while parsing AST

我对我的输入文件使用了我的系统特定头路径的解析示例文件,但我得到ptrdiff_t,'size_t','wchar_t'类型的错误未定义。

I used the 'parsing example file' for my input file with my system specific header paths, but I get errors for 'ptrdiff_t', 'size_t', 'wchar_t' types not defined.

我使用以下标题路径:

/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

Additionally I have also added following, for specifying that the input is c++. These variables are default set to 0 in LangOptions.h

languageOptions.CPlusPlus = 1;//// C++ Support
languageOptions.Bool = 1; //// 'bool', 'true', 'false' keywords.
languageOptions.CXXOperatorNames =1;//// Treat C++ operator names as keywords

错误我得到下面列出。

The errors I get are listed below. Any help to resolve this is appreciated.

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中定义,但我的stddef.h在/ usr / include / linux / stddef.h has

I observe that these should be defined in stddef.h, but my stddef.h in /usr/include/linux/stddef.h has

#ifndef _LINUX_STDDEF_H
#define _LINUX_STDDEF_H

#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif

#endif

感谢您提供任何协助。

Thanks for any help in advance.

可以禁用clang生成与系统头文件相关的诊断。我找不到任何办法做到这一点,因为我不认为有任何直接的方法来做到这一点。

Is it possible to disable clang from generating diagnostics related to system header files.? I couldn't find any way to do this, as I don't think there is any direct way to do this.

推荐答案

虽然Clang和GCC之间的互操作在一定程度上是可能的,但是一些标准库头文件是编译器非常依赖的。实际上,stddef.h和stdarg.h是在创建时与Clang一起生成的 a>。它们被视为内置包含。如果你没有他们,你很有可能无法正常工作。

While interop between Clang and GCC is possible to some extent, some standard library headers are extremely compiler-dependent. In fact, stddef.h and stdarg.h are produced along with Clang when you build it. They are considered "built-in includes". It is very possible that you won't be able to get it to work properly if you don't have them.

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

The good news is that if you have the Clang driver, you probably have the headers too. As they mention on the website, Clang looks for these headers in $(path/to/tool)/../lib/clang/3.3/include.

这篇关于clang在解析AST时不标识“ptrdiff_t”,“size_t”,“wchar_t”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆