gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 15:05:29 29 4
gpt4 key购买 nike

我正在尝试在 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com