[英]S_ISREG macro undefined
問題
這是有問題的代碼
/*we ignore file size for char/block devices, sockets etc*/
if(S_ISREG(fileinfo.st_mode))
uploadfilesize= fileinfo.st_size;
}
它會導致錯誤
error LNK2019: unresolved external symbol _S_ISREG referenced in function _operate file tool_operate.obj
它們在以下問題中被引用
顯然 S_ISREG() 是一堆 posix 宏的一部分,顯然應該告訴我們文件是否是“常規文件”,但我發現的所有示例都有 linux 特定的包含文件。
目前 curl 7.21.5 在 setup.h 中定義了這個:
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
在檢查了 Microsoft 的 sys/stat.h 之后,我發現@OliverZendel 的答案的以下修改對我有用,適用於 Visual Studio 2017,並且希望也適用於其他編譯器:
// Windows does not define the S_ISREG and S_ISDIR macros in stat.h, so we do.
// We have to define _CRT_INTERNAL_NONSTDC_NAMES 1 before #including sys/stat.h
// in order for Microsoft's stat.h to define names like S_IFMT, S_IFREG, and S_IFDIR,
// rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does.
#define _CRT_INTERNAL_NONSTDC_NAMES 1
#include <sys/stat.h>
#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
在 Windows 上嘗試添加下划線 ( _S_ISREG
)。 在 MinGW 的庫中, S_ISREG
宏也可以在<sys/stat.h>
中訪問
也許你應該檢查你的配置宏。
Windows上沒有這樣的東西,你可以使用FindFirstFile,FindNextFile win32 api,返回結構包含類似但不相同的東西。
如果你使用 gcc/mingw 庫,他們有一個 stat() 模擬。 您需要為該宏包含 sys/stat.h。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.