问题
For the question raised in the below link, clang getting include files while parsing AST
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.
I am using below header path:
/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
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>;
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.
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.
回答1:
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.
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
.
来源:https://stackoverflow.com/questions/24407193/clang-not-identifying-ptrdiff-t-size-t-wchar-t-while-parsing-ast