在OSX 10.9.1上使用g++编译时出现错误:未知类型名称'__darwin_wctype_t'。

11

在使用g++从命令行编译基本代码(我附上了一个“hello world”的示例)时,即使在OSX 10.9.1上也会出现问题。

#include <iostream>

int main() {std::cout << "Hello World";}

我使用以下命令进行编译:

g++ hello.cc -o hw

它会产生以下错误消息:


In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ios:215:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iosfwd:90:
In file included from /usr/include/wchar.h:92:
In file included from /usr/include/_wctype.h:47:
/usr/include/_types/_wctype_t.h:31:9: error: unknown type name
      '__darwin_wctype_t'
typedef __darwin_wctype_t wctype_t;
        ^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/string:433:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwchar:107:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/cwctype:55:
In file included from /usr/include/wctype.h:36:
/usr/include/_types/_wctrans_t.h:31:9: error: unknown type name
      '__darwin_wctrans_t'
typedef __darwin_wctrans_t wctrans_t;
        ^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__locale:15:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/string:729:26: error: 
      use of undeclared identifier '__DARWIN_WEOF'
        {return int_type(WEOF);}
                         ^
/usr/include/_wctype.h:50:16: note: expanded from macro 'WEOF'
#define WEOF                    __DARWIN_WEOF
                                ^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/mutex:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__mutex_base:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/chrono:266:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:55:9: error: 
      no member named 'clock_t' in the global namespace
using ::clock_t;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:59:9: error: 
      no member named 'clock' in the global namespace
using ::clock;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:60:9: error: 
      no member named 'difftime' in the global namespace
using ::difftime;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:61:9: error: 
      no member named 'mktime' in the global namespace
using ::mktime;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:62:9: error: 
      no member named 'time' in the global namespace
using ::time;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:63:9: error: 
      no member named 'asctime' in the global namespace
using ::asctime;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:64:9: error: 
      no member named 'ctime' in the global namespace
using ::ctime;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:65:9: error: 
      no member named 'gmtime' in the global namespace
using ::gmtime;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:66:9: error: 
      no member named 'localtime' in the global namespace
using ::localtime;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ctime:67:9: error: 
      no member named 'strftime' in the global namespace
using ::strftime;
      ~~^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:40:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/istream:156:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ostream:132:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/locale:192:
In file included from /usr/include/nl_types.h:94:
/usr/include/_types/_nl_item.h:31:9: error: unknown type name '__darwin_nl_item'
typedef __darwin_nl_item nl_item;
        ^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:40:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/istream:156:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ostream:132:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/locale:2600:27: error: 
      member access into incomplete type 'tm'
    __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
                          ^
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
            const struct tm * __restrict) __DARWIN_ALIAS(wcsftime);
                         ^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:40:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/istream:156:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ostream:132:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/locale:2612:25: error: 
      member access into incomplete type 'tm'
    __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
                        ^
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
            const struct tm * __restrict) __DARWIN_ALIAS(wcsftime);
                         ^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:40:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/istream:156:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ostream:132:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/locale:2624:20: error: 
      member access into incomplete type 'tm'
    __get_year(__tm->tm_year, __b, __e, __err, __ct);
                   ^
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
            const struct tm * __restrict) __DARWIN_ALIAS(wcsftime);
                         ^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:40:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/istream:156:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ostream:132:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/locale:2641:31: error: 
      member access into incomplete type 'tm'
        __get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
                              ^
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
            const struct tm * __restrict) __DARWIN_ALIAS(wcsftime);
                         ^
In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:40:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/istream:156:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ostream:132:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/locale:2646:29: error: 
      member access into incomplete type 'tm'
        __get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
                            ^
/usr/include/wchar.h:131:19: note: forward declaration of 'tm'
            const struct tm * __restrict) __DARWIN_ALIAS(wcsftime);
                         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
我很感激任何人能够为此提供帮助。我经过不懈的搜索,没有找到有用的结果。

我感激你的回答。


我不确定,但是g++是GCC编译器的一部分,从XCode 5.0及以后的版本中被移除了。我认为这会导致异常,因为LLVM C++编译器(Clang)中有自定义类型/常量/宏,而这些在来自GCC的g++中不受支持。你应该尝试使用Clang进行编译。 - art-divin
1
我无法重现您的错误(相同系统)。 - Matthias
这是一个好的想法,但使用clang编译会得到相同的错误信息。这个问题在我从lion升级到mavericks时仍然存在,所以我不认为这是一个特定于mavericks的问题。 - user3198694
你有没有找到解决方案或者解释? - Ken Williams
我在我的.bashrc文件中添加了以下几行代码:export CPLUS_INCLUDE_PATH=/Developer/SDKs/MacOSX10.7.sdk/usr/include/export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/sys/export C_INCLUDE_PATH=$CPLUS_INCLUDE_PATH并附有“用于xcode库”的神秘注释。我不确定当时的意图是什么,也不知道为什么要在.bashrc文件中添加这些内容。 - user3198694
传递 -Hg++ 以了解所有包含的头文件。 - Basile Starynkevitch
2个回答

6
请尝试添加 -I /usr/include,然后再次尝试。
g++ hello.cc -o hw -I /usr/include

我在我的电脑上进行了测试,操作系统为OSX 10.10.3(Yosemite),并发现了更多的问题。

1)当在我的操作系统上使用命令编译时:

 g++ hello.cc -o hw

没有错误信息。

2) 经过几次尝试,我找到了一种重现相同错误输出的方法。命令如下:

 g++ hello.cc -o hw -I /usr/include/sys

输出的错误信息如下:

In file included from hello.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:215:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:90:
In file included from /usr/include/wchar.h:92:
In file included from /usr/include/_wctype.h:47:
/usr/include/_types/_wctype_t.h:31:9: error: unknown type name '__darwin_wctype_t'
typedef __darwin_wctype_t wctype_t;

3) 此外,您可以通过以下命令找到有关编译的更详细信息:

g++ hello.cc -o hw -v

然后,您可以从输出中检查包含的头文件,如下所示。
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
//...... 
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

1

我在MacOS 10.9上使用clang++ 3.9时遇到了类似的错误信息,因此我偶然发现了这个问题。

事实证明,我在头文件中忘记关闭命名空间声明的括号,在包含<iostream>之前发生。在我的设置中,以下代码重现了该问题:

namespace detail {
#include <iostream>

那显然不是楼主的问题,但我希望这会对其他人有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接