unknown type name 'clockid_t'

百般思念 提交于 2019-12-12 14:27:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!