CLOCKS_PER_SEC未声明(首次在此函数中使用)

这是我的程序的一部分;

double get_cpu_time(){ return (double)clock() / CLOCKS_PER_SEC; 

但是我得到以下错误;

在函数'get_cpu_time'中:timertest.c:13:30:error:'CLOCKS_PER_SEC'未声明(在此函数中首次使用)

我已经包含的头文件是;

  #include<stdio.h> #include<math.h> #include <sys/time.h> 

操作系统是Ubuntu12.04(刚刚安装)。

为什么发生?

包括

 <time.h> 

代替

 <sys/time.h> 

根据手册页

 man 3 clock 

您需要包含<time.h>而不是<sys/time.h>