【问题标题】:Compilation error for using struct itimerspec使用 struct iterspec 的编译错误
【发布时间】:2015-05-11 18:28:43
【问题描述】:

我正在尝试使用 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 ctimer.c -o ctimer.

标签: c


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-10
    • 2014-09-03
    • 2019-02-14
    相关资源
    最近更新 更多