首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复MacOSX上缺少时间相关的全局命名空间中没有成员的错误?

如何修复MacOSX上缺少时间相关的全局命名空间中没有成员的错误?
EN

Stack Overflow用户
提问于 2014-10-03 20:52:15
回答 3查看 9.6K关注 0票数 13

我正在尝试在Maverick10.9的命令行上编译一个项目。该项目可以在Linux上完美地编译。显然,MacOSX上的ctime似乎有一个问题。错误是

代码语言:javascript
复制
$ make
Compiling src//core/AbstractARAClient.cpp
In file included from src//core/AbstractARAClient.cpp:5:
In file included from include/AbstractARAClient.h:8:
In file included from include/ARAMacros.h:14:
In file included from include/Address.h:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ostream:131:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/mutex:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__mutex_base:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:279:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ctime:56:9: error: no member named
      'clock_t' in the global namespace
using ::clock_t;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ctime:58:9: error: no member named
      'time_t' in the global namespace; did you mean 'size_t'?
using ::time_t;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include/stddef.h:42:23: note: 
      'size_t' declared here
typedef __SIZE_TYPE__ size_t;

In file included from src//core/AbstractARAClient.cpp:5:
In file included from include/AbstractARAClient.h:8:
In file included from include/ARAMacros.h:14:
In file included from include/Address.h:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ostream:131:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:18:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/mutex:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__mutex_base:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/chrono:279:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ctime:60:9: error: no member named
      'clock' in the global namespace
using ::clock;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ctime:61:9: error: no member named
      'difftime' in the global namespace
using ::difftime;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ctime:62:9: error: no member named
      'mktime' in the global namespace
using ::mktime;
      ~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ctime:63:9: error: no member named
      'time' in the global namespace
using ::time;

我在网上搜索过,如果项目中有名为“time.h”的头文件,似乎会出现问题(就像这个项目中的情况一样)。ctime的实际不完整实现似乎也存在问题(但通常人们通过xcode安装命令行实用程序)。

我想知道一般的问题是什么,最后是如何在mac上实际编译代码。相反,对于存储库中的代码,我已经在Makefile的第53行添加了一个stdlib选项

代码语言:javascript
复制
CFLAGS_DEBUG = -g -Wall -stdlib=libc++

在Makefile的前一行中已经设置了C++11选项。

提亚

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-02-18 23:48:45

答案或多或少是显而易见的。该项目包含一个头Time.h (和相应的类Time)。不幸的是,MacOSX文件系统不区分大小写,这意味着这与/usr/include中现有的time.h冲突。

您可以在Time.h之前包含系统time.h (意思是#include <ctime>),也可以简单地将您的文件重命名为其他名称(例如MyTime.h)。

票数 14
EN

Stack Overflow用户

发布于 2018-12-16 13:04:40

检查系统上是否存在/usr/local/include/time.h,如果存在则将其删除。

票数 8
EN

Stack Overflow用户

发布于 2016-08-25 08:50:29

有一种不同的方法来解决这个问题,哪个IMHO更好。我写这篇文章是为了下次遇到这个错误时,我可以很容易地找到答案,并且忘记了解决方案(在几年内?)

进入Xcode并从构建阶段中删除"Headers“部分中包含的项目文件。

这将防止编译器的不当操作,包括从您的空间(应该只(或至少最后排序)可通过“Time.h”访问)

这实际上告诉Xcode“不,我不想像搜索库一样搜索我自己的头文件,因为它是我自己的项目”

它可能还有其他次要影响,但至少对我的用途来说,这比重命名我的"Time.h“要好。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26179298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档