Ошибка при компиляции с g++ в OSX 10.9.1: неизвестное имя типа '__darwin_wctype_t' - программирование
Подтвердить что ты не робот

Ошибка при компиляции с g++ в OSX 10.9.1: неизвестное имя типа '__darwin_wctype_t'

При компиляции даже базового кода (например, я присоединяю мир hello) в OSX 10.9.1 из командной строки с g++

#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.

Я ценю любой свет, который любой может пролить на это. Ни один из моих усердных googling ничего не сделал.

4b9b3361

Ответ 1

Не могли бы вы повторить попытку после добавления -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.

Ответ 2

У меня появилось подобное сообщение об ошибке на MacOS 10.9 с clang++ 3.9, поэтому я наткнулся на этот вопрос.

Оказывается, я забыл закрыть скобку объявления пространства имен в файле заголовка, который был включен до <iostream>. В моей настройке следующий код воспроизводит проблему:

namespace detail {
#include <iostream>

Это, очевидно, не проблема ОП, но я надеюсь, что это поможет другим.