uses undefined struct compile error – C

uses undefined struct compile error – C

风苍溪 发布于 2021-11-24 字数 810 浏览 842 回复 4 原文

The compiler doesn't know where stat.h is?

c:ProjectsADC_HCImongoose.c(745) : error C2079: 'st' uses undefined struct '_stat64'

#include <sys/types.h>
#include <sys/stat.h>

static int
mg_stat(const char *path, struct mgstat *stp)
    struct  _stat64 st; //<-- ERROR

    int     ok;
    wchar_t     wbuf[FILENAME_MAX];

    to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
    if (_wstat64(wbuf, &st) == 0) {
        ok = 0;
        stp->size = st.st_size;
        stp->mtime = st.st_mtime;
        stp->is_directory = S_ISDIR(st.st_mode);
    } else {
        ok = -1;

    return (ok);

...downloaded the files straight from the source.

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。



需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。


吃→可爱长大的 2022-06-07 4 楼

I suggest you to sync to SVN trunk.

If you don't have SVN client, simply download two files: (and .c file too)

The reason is that recently the code was refactored, and CRT _stat function was substituted
with WinAPI one, GetFileAttributesExW().

爱情眠于流年 2022-06-07 3 楼

Change the _stat64 to stat64. At least in my Linux machines that's the name of the structure. I don't know if it is different in Windows.

Note that neither _stat64 nor __stat64 is 'standard' in the sense of documented by any standard, such as POSIX. You would normally use struct stat; if you are worried about whether that will work with big files (over 2 GiB), then check what compilation options are required on your platform to obtain 'large file support'. For 64-bit machines and 64-bit compilations (not necessarily Windows 64), you usually don't need to worry. You can often obtain large file support using:


These are at least semi-standardized. Systems such as autoconf detect these things automatically (if you ask them to do so).

吾性傲以野 2022-06-07 1 楼

See MSDN: _wstat64 takes a parameter of struct __stat64 (with two underscores). Redeclare your variable st to be of type struct __stat64.