我需要递归搜索给定文件名的一个UNC路径(request
),我已经成功连接到路径,并找到了搜索here的答案,但是,当我编译我的程序,我得到了以下错误:递归搜索一个目录,我不明白的编译错误
find-util.c: In function ‘char* search_utils(const char*, int, bool)’:
find-util.c:51:16: error: ‘struct dirent’ has no member named ‘d_type’
if (ent->d_type == DT_DIR)
^
find-util.c:51:26: error: ‘DT_DIR’ was not declared in this scope
if (ent->d_type == DT_DIR)
^
我在Ubuntu 16.04是使用mingw
编译器交叉编译,以便能够在Windows 7上运行我缺少一个库?或者还有其他事情我没有看到?
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dirent.h>
#include <string.h>
static char *search_utils(const char *request, int depth, bool verbose)
{
DIR *dir;
struct dirent *ent;
puts("Connecting to mgtutils..");
if ((dir = opendir(MG_PATH)) != NULL)
{
while ((ent = readdir(dir)) != NULL)
{
if (verbose == true)
{
printf("Searching%s for %s\n", ent->d_name, request);
}
if (ent->d_type == DT_DIR)
{
if ((strlen(MG_PATH) + strlen(ent->d_name) + 1) > PATH_MAX)
{
puts("Path to long, cannot");
}
}
}
}
}
Linux的Ubuntu 16.04,mingw编译器交叉编译到Windows 7 – justAnotherCat
嗯。 'readdir()'在Windows上不存在。 win32 API改为提供FindFirst()FindNext()。然而,mingw可能会像'readdir()'一样将它包装到Posix中。 (我不知道。)因此,我的答案的底部可能会导致你进入正确的方向... – Scheff
思考两次我关心什么标题用于交叉编译。仔细阅读'gcc'的命令行调用(尤其是包含'-I'参数之后的目录)应该给出提示。我从来没有这样做过,但我知道有人在Linux/mingw之间交叉编译Windows的库。如果你被困住了,我可以问他... – Scheff