错误:未声明'CLOCK_MONOTONIC'(首次在此函数中使用)
error: 'CLOCK_MONOTONIC' undeclared (first use in this function)
我尝试在opencv 3.0中构建基于像素强度比较的对象检测(pico)代码,在构建时遇到类似错误的错误:"CLOCK_MONOTONIC"未声明(首次在此函数中使用)。谁能说出如何克服这些问题??代码如下以及我得到的错误
float getticks()
{
struct timespec ts;
if(clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
{
printf("clock_gettime errorn");
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
添加命令行开关:编译时-D_POSIX_C_SOURCE=199309L
。
没有它,time.h 标头将无法定义它。
相关文章:
- 函数未在作用域中声明 / 如何结合使用 header.h、header.cpp 和 main.cpp?
- 我的函数调用 (C++) 中的未声明标识符
- 未定义与已删除与未声明的函数
- C++ 在 CentOS7 中与 g++ 的 DLL 链接后未声明的函数
- 由于值返回函数中的错误,程序无法编译.它说未声明的标识符
- 为什么 C 允许我调用未声明的函数?
- 'temp'未声明,请先使用此函数
- C 如何从构造函数中声明(错误C2065未宣布的标识符)
- 函数未在此范围内声明
- 尝试使用 std::函数(未定义的符号)声明模板化类状态时出现链接错误
- makefile 和 lex+yacc 中的错误 -> 错误:"noyywrap"未声明(在此函数中首次使用)
- 我们如何有证据表明,声明虚拟函数的类是2个字节,其中一个不超过一个未声明,而在子类中
- 函数参数中未声明和未定义的标识符
- 在此范围错误中未声明函数错误
- 类 'MainWindow' 中未声明任何成员函数
- 错误C2509:成员函数未在派生类中声明
- C++成员函数未声明错误时(当它看起来是错误时)
- 函数未声明(首先使用此函数)
- 函数未声明简单程序
- 无法调用 VBO 实现所需的函数...未声明错误