c - Trying to use clock_gettime(), but getting plenty of "undeclared" errors from time.h -



c - Trying to use clock_gettime(), but getting plenty of "undeclared" errors from time.h -

this question has reply here:

linux: gcc -std=c99 complains not knowing struct timespec 2 answers

i trying measure running time of function using clock_gettime(). including time.h, added -lrt makefile, , added right path on eclipse cdt. however, when seek compile maintain getting these kinds of errors:

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 type of clock_ seek use. i've been reading plenty of questions/answers , tutorials haven't been able find helps.

the headers i'm including are:

#include <stdlib.h> #include <stdio.h> #include <math.h> #include <time.h>

i'm on ubuntu 13.10 32 bit , compiling on gcc next cflags: -g -wall -pedantic -std=c99

if add together flag -d_posix_c_source=199309l error: unknown type name ‘timespec’ , warnings using timespec.

this part of code, in case helps:

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);

thanks

putting this , this answers able create work. had add together _posix_c_source macro, create sure preprocessor getting library features correctly, did adding line before includes:

#define _posix_c_source 199309l

then started getting unknown type name timespec error, happening because have tell compiler explicitly timespec struct. fixed writing:

struct timespec time1, time2;

instead of timespec time1, time2;.

c time libraries

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -