I am trying to measure the running time of a function using clock_gettime() . I include time.h , I added -lrt to the Makefile and added the correct path to the Eclipse CDT. However, when I try to compile, I keep getting errors like this:
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);
This happens with any type of CLOCK_ that I am trying to use. I read a lot of questions / answers and tutorials, but could not find something that helps.
In the headers I include:
#include <stdlib.h> #include <stdio.h> #include <math.h> #include <time.h>
I'm on Ubuntu 13.10 32 bit and compiling on gcc with the following CFLAGS : -g -Wall -pedantic -std=c99
If I add the flag -D_POSIX_C_SOURCE=199309L , I get error: unknown type name 'timespec' and warnings about using timespec .
This is part of the code, just in case it helps:
timespec time1, time2; int temp; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); . . . clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
thanks
source share