Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: 'CLOCK_MONOTONIC' undeclared (first use in this function)

Tags:

c++

c

opencv

I tried to build the Pixel Intensity Comparison-based Object detection (pico) code in opencv 3.0, while building i got an error like error: 'CLOCK_MONOTONIC' undeclared (first use in this function) . Can any tell how to overcome these issues?? The code is as follows along with the error i got

float getticks()
{
    struct timespec ts;

    if(clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
    {
        printf("clock_gettime error\n");

        return -1.0f;
    }

    return ts.tv_sec + 1e-9f*ts.tv_nsec;
}

and the error i got as

picolrn.c:94:18: error: storage size of 'ts' isn't known
  struct timespec ts;
                  ^
picolrn.c:96:19: error: 'CLOCK_MONOTONIC' undeclared (first use in this function)
  if(clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
                   ^
picolrn.c:96:19: note: each undeclared identifier is reported only once for each function it appears in
make.exe[2]: *** [build/Debug/MinGW_1-Windows/picolrn.o] Error 1
like image 919
Jaya Balaji Venkatachalam Avatar asked Apr 16 '15 06:04

Jaya Balaji Venkatachalam


1 Answers

Add a commandline switch: -D_POSIX_C_SOURCE=199309L when compiling.

Without it, time.h header will not define it.

like image 161
Bram Avatar answered Nov 17 '22 23:11

Bram