c++ - 如何修复 MacOSX 上全局命名空间错误中与缺失时间相关的无成员?

标签 c++ macos clang++ ctime

我正在尝试在 Maverick 10.9 的命令行上编译一个项目。该项目在 Linux 上完美编译。显然,MacOSX 上的 ctime 似乎存在问题。错误是

$ 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 上实际编译代码。相反,对于存储库中的代码,我在第 53 行的 Makefile 中添加了一个 stdlib 选项

CFLAGS_DEBUG = -g -Wall -stdlib=libc++

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

TIA

最佳答案

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

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

关于c++ - 如何修复 MacOSX 上全局命名空间错误中与缺失时间相关的无成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26179298/

相关文章:

c++ - 数组大小未定义? C++

macos - M1 Mac 上的 VSCode 不会在终端中运行 "dotnet ef"命令

c++ - 我应该如何最好地从 OS X 上的 svn 安装和使用 libc++

clang++ - 如何禁用 Clang 警告 "no case matching constant switch condition"

c++ - 什么是 clang++ 选项以便在 GDB 中我可以使用 std::cout 作为函数参数

c++ - 运算符的例子 -> 重载

c++ - 解析字符串参数数组

c++ - Unique_ptr 和前向声明

ruby - 使用 RVM 安装 Ruby 2.1.3 时出错

iphone - 如何恢复所有那些好的旧 Xcode 功能?