问题
I am trying to use C code written on a Linux platform on Mac OS X. I am running into an error related to timers:
../src/stinger/timer.c:61:1: error: unknown type name 'clockid_t'
../src/stinger/timer.c:74:2: error: #error "Cannot find a clock!"
which points to this section of code.
static clockid_t clockid;
#if defined(CLOCK_REALTIME_ID)
#define CLKID CLOCK_REALTIME_ID
#define CLKIDNAME "CLOCK_REALTIME_ID"
#elif defined(CLOCK_THREAD_CPUTIME_ID)
#define CLKID CLOCK_THREAD_CPUTIME_ID
#define CLKIDNAME "CLOCK_THREAD_CPUTIME_ID"
#elif defined(CLOCK_REALTIME_ID)
#warning "Falling back to realtime clock."
#define CLKID CLOCK_REALTIME_ID
#define CLKIDNAME "CLOCK_REALTIME_ID"
#else
#error "Cannot find a clock!"
#endif
What is the cause of this error? Where should the type clockid_t
come from?
回答1:
If I remember correctly all the "clock" stuff is part of the "realtime" extension of POSIX that isn't implemented by OSX. So you will not have luck with that. You'd have to use OSX specific features to have a clock at a good resolution.
Edit: In P99 I have a wrapper code for OSX for the similar C11 function timespec_get
. No Idea if this really functional, I don't have a Mac, but you could have a look, there. (file is "p99_threads.h")
来源:https://stackoverflow.com/questions/13472761/unknown-type-name-clockid-t