error: unknown type name '__darwin_wctype_t' typedef __darwin_wctype_t wctype_t compiling on MacOS with Clang

error: unknown type name '__darwin_wctype_t' typedef __darwin_wctype_t wctype_t compiling on MacOS with Clang

全新的项目完全没问题,但我发现了一个很老的开源项目,想编译它。基本上,包含 headers 时会出现错误,例如 iostreamalgorythm

我的环境如下所示:

  1. MacOS 10.15.4
  2. 叮当声 11.0.3
  3. CMake 3.16.5
  4. 这里安装了工具和headers/Library/Developer/CommandLineTools/usr/bin
  5. 项目使用 cotire 1.8.0
  6. IDE - CLion

一般来说,项目由 30 多个 sub-projects 组成,有些是 C,有些是 C++。只能构建 C 中的那些。

我一直在尝试很多东西:为 Cmake 设置目标版本,设置手动查找 headers 的路径(在 Cmake 文件中)。 Re-installing 开发人员工具也无济于事。

请查看原始错误消息:

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:37:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:214:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iosfwd:95:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/wchar.h:118:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/wchar.h:92:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_wctype.h:42:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/__wctype.h:62:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_types/_wctype_t.h:32:9: error: unknown type name '__darwin_wctype_t'
typedef __darwin_wctype_t wctype_t;

更新 1 我向前移动了一点,发现 stdafx.h 甚至不能包含 iostream。所以我会检查所有包含路径。

包含有问题。项目有自己的_types.h,系统里也有。首先包含项目的变体,而系统的变体被忽略。显然,这会导致此类神秘消息。

This is a root cause.Clang's documentation says I need to use -isysroot to explicitly set system's headers root and this will prevent matching project's header first, 但它对我不起作用.暂时改了项目的header名称(types.h)效果很好(没有下划线就不再被认为是系统header),同时我会尽量修复它