问题
I'm trying to compile a project on the command line on Maverick 10.9. The project compiles perfectly on Linux. Apparently, there seems to be an issue with ctime on MacOSX. The errors are
$ 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;
I've searched the web and there seems to be an issue if there are headers in a project which are named 'time.h' (like it is the case in this project). There also seems generally to be a problem with an actual incomplete implementation of ctime (but generally people refer to install command line utils via xcode).
I'm wondering what the general issue is and finally how to actually compile the code on mac. In contrast, to the code in the repository, I've added to the Makefile in line 53 a stdlib option
CFLAGS_DEBUG = -g -Wall -stdlib=libc++
The C++11 option is already set in a previous line of the Makefile.
TIA
回答1:
The answer is more or less obvious. The project contains a header Time.h
(and corresponding class Time
). Unfortunately, the MacOSX file system is case insensitive, meaning that this conflicts with the existing time.h
in /usr/include
.
You can either include the systems time.h (meaning #include <ctime>
) beforehand the Time.h
or simply rename your file to something else (e.g. MyTime.h
).
回答2:
There is a different way to solve this, which IMHO is better. I write this so I can find the answer easily next time I hit this error and have forgotten the solution (in a couple years?)
Go into Xcode and remove the project files included in the "Headers" section from the Build phases.
This will prevent the inappropriate action of the compiler including from your space (which should only (or at least ordered last) be accessible via "Time.h")
This essentially tells Xcode "No I do not want to search my own headers as if they were a library, because it is my own project"
It probably has other secondary repercussions but, at least for my uses, this is better than renaming my "Time.h"
回答3:
Check if /usr/local/include/time.h
exists on your system, remove it if it exists.
来源:https://stackoverflow.com/questions/26179298/how-to-fix-missing-time-related-no-member-in-global-namespace-errors-on-macosx