【发布时间】:2017-01-06 16:05:30
【问题描述】:
clock_gettime 不再适用于 MacOS Sierra。很确定在 Xcode 8 出来之前我已经正确编译了。我真的有点坚持如何让它正确编译。
#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);
}
这样的代码根本无法编译。我被告知 sierra 计时库已经改变。我得到一个编译器错误,因为 CLOCK_MONOTONIC 没有被定义,并且一个警告 clock_gettime 的隐式声明,如果我将 CLOCK_MONOTONIC 定义为随机的东西,这会变成一个错误,因为它只是在链接阶段出错。
有人知道编译和执行代码的修复或解决方法吗?
【问题讨论】: