我试图测量使用clock_gettime()
功能的运行时间获得足够的“未申报”的错误。我包括time.h
,我加-lrt
的Makefile文件,并添加基于Eclipse CDT正确的道路。然而,当我尝试编译我不断收到这两种错误:尝试使用clock_gettime(),但是从time.h中
experiments.c: In function ‘main’:
experiments.c:137:2: error: unknown type name ‘timespec’
timespec time1, time2;
^
experiments.c:139:2: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration]
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
^
experiments.c:139:16: error: ‘CLOCK_PROCESS_CPUTIME_ID’ undeclared
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
这种情况与任何类型的CLOCK_
我尝试使用。我一直在阅读大量的问题/答案和教程,但一直没能找到有帮助的东西。
我包括标头是:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
我在Ubuntu 13.10 32位和具有以下CFLAGS
编制上gcc
:-g -Wall -pedantic -std=c99
如果我添加了标志-D_POSIX_C_SOURCE=199309L
我得到error: unknown type name ‘timespec’
并警告使用timespec
。
这是代码的一部分,以防万一它有助于:
timespec time1, time2;
int temp;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
.
.
.
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
/*code stuff*/
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
感谢
你包含哪些头文件? – Grantly 2014-11-05 23:30:50
关于'_POSIX_C_SOURCE> = 199309L'的手册页中有一个注释,你试图编译它的是什么? – 2014-11-05 23:49:32
@ DavidC.Rankin上的gcc编译具有以下标志:-g -Wall -pedantic -std = C99 – Francisca 2014-11-05 23:57:44