c - 在 c99 中使用 clock_gettime 时出现编译错误

标签 c c99

当我在我的代码片段中使用 clock_gettime,并使用标志 -std=c99 进行编译时,我得到了这样的错误:

warning: implicit declaration of function 'clock_gettime'
error: 'CLOCK_REALTIME' undeclared (first use in this function)

并且我包含了文件“time.h”。 任何人都知道如何修复它。

最佳答案

在您使用 -std=c99 的原始代码中,尝试添加

#define _POSIX_C_SOURCE >= 199309L

clock_gettime 的手册页表明这是一项必要的功能测试宏要求。

关于c - 在 c99 中使用 clock_gettime 时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13069758/

相关文章:

c - 如何将字符串文字与 4 的倍数的地址对齐?

c - 将字符附加到字符串末尾的函数

c - 为什么 scanf() 在处理字符串时不接受用户的输入?

c - trie 中未初始化的值

c - MinGW错误 "undefined reference to '类型''"

c - 是否有跨平台检测 C99 的预处理器宏?

c - 使数组内容易变的正确语法?

c - C99 不支持函数重载有什么原因吗?

在 C 中将短语转换为数字

c - 将 struct 指针类型的 struct 成员初始化为 null