在 windows 上制作 mosquitto-auth-plug

make mosquitto-auth-plug on windows

我目前正在尝试在 windows 上构建 mosquitto-auth-plugin,但我不确定要使用哪个 make 进程。文档说要编辑我已经完成的 config.mk 文件,然后到 'make' auth-plug——这是令我震惊的,我曾尝试使用 GnWin 和 MinGW 来制作,但都没有用有一种方法可以在 windows 上构建库,或者我可以在 Linux 中构建它并将 auth-plug.o 复制到我的 windows 机器上吗?

我不知道有人试图在 Windows 上构建 mosquitto-auth-plug,如果成功的话,我会感到非常惊讶;作为插件的作者,我没有注意 Un*x 之外的可移植性,为了不抱希望,我不会。 :-)

也就是说,您不能在 Windows 上 运行(加载)基于 Linux 构建的共享对象。有什么可能,但我已经有很多年没有做过类似的事情了,那就是使用适当的工具链进行交叉编译。

我为 Windows 构建它,仅使用 HTTP 和 JWT 后端。

必须修复:

  1. 将 __declspec(dllexport) 放入 mosquitto_auth_Xyz... auth-plug.c.
  2. 中的函数
  3. 在 auth-plug.c 中添加了 fnmatch(a,b) 和 strsep() 的替代代码,见下文。
  4. 在 log.c 中,我转而使用 log=__log 而不是 log=mosquitto_log_printf,因为我从 libmosquitto 导入函数失败。
  5. 使用 Visual Studio 2017 Express 编译,预处理器定义 _CRT_NONSTDC_NO_DEPRECATE 和 _CRT_SECURE_NO_WARNINGS 到位。

代码运行良好!

对于 auth-plug.c 中的 fnmatch(a,b) 和 strsep(),将 #include 更改为:

#ifdef _WIN32
#include <windows.h>
#include <shlwapi.h>
#define fnmatch(a, b, c) PathMatchSpecA(a, b)
extern char* strsep(char** stringp, const char* delim)
{
    char* start = *stringp;
    char* p;

    p = (start != NULL) ? strpbrk(start, delim) : NULL;

    if (p == NULL)
    {
        *stringp = NULL;
    }
    else
    {
        *p = '[=10=]';
        *stringp = p + 1;
    }

    return start;
}
#else
#include <fnmatch.h>
#endif