clock_gettime
doesn't work on MacOS Sierra anymore. Pretty sure I had this compiling correctly before Xcode 8 came out. I am really kind of stuck on what to do to get it to compile correctly.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int main(){
struct timespec time1, time2;
clock_gettime(CLOCK_MONOTONIC,&time1);
//Some code I am trying to work out performance of...
clock_gettime(CLOCK_MONOTONIC,&time2);
printf("Time Taken: %ld",time2.tv_nsec - time1.tv_nsec);
}
Code like this simply fails to compile. I've been told the sierra timing library has changed. I get a compiler error for CLOCK_MONOTONIC
not being defined and a warning for implicit declaration of clock_gettime
, which turns into an error if I define CLOCK_MONOTONIC
to something random, as it then just errors out during the linking stage.
Does anyone know of a fix or workaround to get the code compiling and executing?