Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unknown type name 'clockid_t'

Tags:

c

posix

macos

timer

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?

like image 646
clstaudt Avatar asked Mar 12 '26 05:03

clstaudt


1 Answers

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")

like image 169
Jens Gustedt Avatar answered Mar 14 '26 23:03

Jens Gustedt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!