【问题标题】:O_DIRECT not defined on Arch LInuxArch LINux 上未定义 O_DIRECT
【发布时间】:2020-11-23 10:22:33
【问题描述】:

我正在尝试编写一些低延迟磁盘访问代码。问题是我正在使用的库具有以下代码:

#ifdef O_DIRECT
  int flags = O_DIRECT;
#else
  int flags = 0;
#endif

我的安装没有定义O_DIRECT。 我已经通过这个简单的程序确认了这一点:

#include <stdio.h>

int main(void){
#ifdef O_DIRECT
        printf("O_DIRECT");
#else
        printf("Otherwise");
#endif
}

打印Otherwise

所以问题是为什么没有定义?另外如何解决这个问题?

【问题讨论】:

    标签: linux hard-drive gcc


    【解决方案1】:

    宏其实是defined in&lt;fcntl.h&gt;,不是stdio.h。

    其次,要访问定义,您需要#define _GNU_SOURCE,因为它是Linux-specific。请注意,定义必须在 any libc 标头包含之前,而不仅仅是在 fcntl.h 之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 2017-09-12
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 2021-10-05
      • 2011-01-08
      相关资源
      最近更新 更多