簡體   English   中英

&#39;DT_REG Undeclared&#39; 即使在使用時<dirent.h>函數中的頭文件

[英]'DT_REG Undeclared' even when using <dirent.h> header file in function

我在引用 DT_REG 的函數中使用了 <dirent.h> 頭文件,但是,我收到錯誤消息“'DT_REG' undeclared (first use in this function)”

代碼片段是:

  DIR * dirp;
  struct dirent * entry;
  dirp = opendir(path);
  if(entry->d_type == DT_REG) { //.... }

在我的 makefile 中,我使用了“cc -std=c11 -Wall -Werror -pedantic”。

有什么想法嗎?

DT_REG不是 ISO C11 擴展的一部分。 設置-std=c11嚴格僅啟用 C11 標准中定義的功能。

您可以使用功能宏來啟用其他擴展。 正如readdir 手冊所述,您需要_DEFAULT_SOURCE宏來啟用文件類型常量。

您可以在包含dirent.h之前在源代碼中執行此操作

#define _DEFAULT_SOURCE
#include <dirent.h>

或通過命令行作為編譯器選項

cc -std=c11 -D_DEFAULT_SOURCE -Wall -Werror -pedantic

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM