错误:“CLOCK_MONOTONIC”未声明(在此函数中首次使用)

问题描述 投票:0回答:1

我尝试在 opencv 3.0 中构建基于像素强度比较的对象检测(pico)代码,在构建时出现类似 error: 'CLOCK_MONOTONIC' undeclared (first use in this function) 的错误。谁能告诉我如何克服这些问题吗?代码如下以及我得到的错误

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

我得到的错误是

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
c++ c opencv
1个回答
12
投票

编译时添加命令行开关:

-D_POSIX_C_SOURCE=199309L
。时钟 ID 与
clock_gettime(3)
一起记录,其中指出需要此 功能测试宏

没有它,time.h头不会定义它。

© www.soinside.com 2019 - 2024. All rights reserved.