gpt4 book ai didi

c++ - 错误 : 'CLOCK_MONOTONIC' undeclared (first use in this function)

转载 作者:太空狗 更新时间:2023-10-29 20:57:42 26 4
gpt4 key购买 nike

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

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

最佳答案

编译时添加命令行开关:-_POSIX_C_SOURCE=199309L

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

关于c++ - 错误 : 'CLOCK_MONOTONIC' undeclared (first use in this function),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29666937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com