gpt4 book ai didi

使用 struct itimerspec 的编译错误

转载 作者:行者123 更新时间:2023-11-30 17:14:48 29 4
gpt4 key购买 nike

我正在尝试使用timerfd_create() 和timer_settime() 用C 语言编写一个计时器。我正在使用 CLOCK_MONOTONIC。但是尽管我包含了这些头文件,

#include <sys/timerfd.h>
#include <sys/time.h>
#include <sys/types.h>

struct itimerspec timerValue; //This is how i defined the structure
//some code
g_fdRetryTimer = timerfd_create(CLOCK_MONOTONIC, 0);

我不断收到以下编译错误。

error: storage size of ‘timerValue’ isn’t known
error: ‘CLOCK_MONOTONIC’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)

请帮忙!谢谢。

最佳答案

gcc < 5.1.0 默认标准是 -std=gnu90。版本 5.1.0,将默认值从 -std=gnu90 更改为 -std=gnu11

您应该使用 -std=gnu99 编译代码,以使标识符 CLOCK_MONOTONIC 可用。

This answer可能会提供更多详细信息。

关于使用 struct itimerspec 的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30175023/

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