【COCOS2DX-ANDROID-游戏开发之十九】android编译之ctime:66: error: ‘::clock_t’ has not been declared

来源:互联网 发布:js获取div name 编辑:程序博客网 时间:2024/04/28 07:56

编译android 报错,ctime:66: error: ‘::clock_t’ has not been declared,诡异的问题如下图:


报一个gnu的C++标准库的ctime的错误

程序中根本木有调用<ctime>,那这个诡异的问题是怎么来的呢?


后来发现我有一个类Time.h和Time.cpp,对就是这货,且不管为什么GNU为什么不识别大小写,为什么和标准库的<time.h>起冲突,但这个诡异的问题足以告诉我们:

一定不要起类名和标准库一样的名字,否则暂时木有问题,早晚会自食苦果的~~


------------------------------------------------------------

国外的盆友也遇到类似的问题:给个copy

So I lost a bit of time to this compiler error coming from a MacBook and OSX 10.5:


/usr/include/c++/4.0.0/ctime:66: error: ‘::clock_t’ has not been declared
/usr/include/c++/4.0.0/ctime:68: error: ‘::tm’ has not been declared
/usr/include/c++/4.0.0/ctime:70: error: ‘::clock’ has not been declared
/usr/include/c++/4.0.0/ctime:71: error: ‘::difftime’ has not been declared
/usr/include/c++/4.0.0/ctime:72: error: ‘::mktime’ has not been declared
/usr/include/c++/4.0.0/ctime:73: error: ‘::time’ has not been declared
/usr/include/c++/4.0.0/ctime:74: error: ‘::asctime’ has not been declared
/usr/include/c++/4.0.0/ctime:75: error: ‘::ctime’ has not been declared
/usr/include/c++/4.0.0/ctime:76: error: ‘::gmtime’ has not been declared
/usr/include/c++/4.0.0/ctime:77: error: ‘::localtime’ has not been declared
/usr/include/c++/4.0.0/ctime:78: error: ‘::strftime’ has not been declared
/usr/include/c++/4.0.0/bits/locale_facets.tcc: In member function ‘_InIter std::time_get<_CharT, _InIter>::_M_extract_via_format(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, tm*, const _CharT*) const’:
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1794: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1801: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1809: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1816: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1828: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1835: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1838: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1850: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1855: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1863: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1867: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1887: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1923: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc:1931: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc: In member function ‘virtual _InIter std::time_get<_CharT, _InIter>::do_get_weekday(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, tm*) const’:
/usr/include/c++/4.0.0/bits/locale_facets.tcc:2157: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc: In member function ‘virtual _InIter std::time_get<_CharT, _InIter>::do_get_monthname(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, tm*) const’:
/usr/include/c++/4.0.0/bits/locale_facets.tcc:2203: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’
/usr/include/c++/4.0.0/bits/locale_facets.tcc: In member function ‘virtual _InIter std::time_get<_CharT, _InIter>::do_get_year(_InIter, _InIter, std::ios_base&, std::_Ios_Iostate&, tm*) const’:
/usr/include/c++/4.0.0/bits/locale_facets.tcc:2230: error: invalid use of undefined type ‘struct tm’
/usr/include/wchar.h:152: error: forward declaration of ‘struct tm’


The answer is that is that the Mac OS X GCC compile environment is funny about case sensitivity and redefining things.  In this case somewhere in my -I/mylibpath/include/  was a file Time.h.  The system saw this as a redefinition of time.h and got all confused.  Note that I didn’t even use that Time.h in my main.c, nor did any header I used call it.  It just saw the file from my -I/path/.   I renamed the file to oTime.h and did a find/replace on all affected library files and I was on to the next compiler error.  Of course that turned out to be an undefined INT_MAX.  Same problem different file.  In the includes, there was a Limits.h that included limits.h but added to defines.  Once again, Limits.h becomes oLimits.h and a find/replace (I’m playing with TextWrangler for this).  Good luck.


原创粉丝点击