Erlang:找不到指定的模块

发布于 2024-08-03 03:17:13 字数 2222 浏览 4 评论 0原文

我有一个最低限度的 Erlang 端口驱动程序:

erl_driver_bridge.c -> erl_driver_bridge.dll

#define __WIN32__

#include "erl_driver.h"

typedef struct {
    ErlDrvPort port;
} erl_driver_bridge_data;

static ErlDrvData bridge_start(ErlDrvPort port, char *buff) {
    erl_driver_bridge_data* d =
        (erl_driver_bridge_data*)driver_alloc(sizeof(erl_driver_bridge_data));
    d->port = port;
    return (ErlDrvData)d;
}

static void bridge_stop(ErlDrvData data) {
    driver_free((char*)data);
}

static void bridge_output(ErlDrvData data, char *buff, int bufflen) {
    erl_driver_bridge_data* d = (erl_driver_bridge_data*)data;
}

ErlDrvEntry erl_driver_bridge_entry = {
    NULL,               /* F_PTR init, N/A */
    bridge_start,       /* L_PTR start, called when port is opened */
    bridge_stop,        /* F_PTR stop, called when port is closed */
    bridge_output,      /* F_PTR output, called when erlang has sent */
    NULL,               /* F_PTR ready_input */
    NULL,               /* F_PTR ready_output */
    "erl_driver_bridge", /* char *driver_name, the argument to open_port */
    NULL,               /* F_PTR finish, called when unloaded */
    NULL,               /* Not used */
    NULL,               /* F_PTR control, port_command callback */
    NULL,               /* F_PTR timeout, reserved */
    NULL,               /* F_PTR outputv, reserved */
    NULL,               /* F_PTR ready_async */
    NULL,               /* F_PTR flush */
    NULL,               /* F_PTR call */
    NULL,               /* F_PTR event */
    ERL_DRV_EXTENDED_MARKER,
    ERL_DRV_EXTENDED_MAJOR_VERSION,
    ERL_DRV_EXTENDED_MINOR_VERSION,
    0,
    NULL,               /* Reserved -- Used by emulator internally */
    NULL,               /* F_PTR process_exit */
};

DRIVER_INIT(erl_driver_bridge) {
    return &erl_driver_bridge_entry;
}

然后我尝试在 Erlang 中加载它:

case erl_ddll:load_driver(".", erl_driver_bridge) of
    ok -> ok;
    {error, Error} -> erl_ddll:format_error(Error)
end.

这会产生:

找不到指定的模块。

我已经检查了驱动程序是否存在于当前目录中,甚至指定了完整路径,但 Erlang 仍然看不到它。有什么想法吗?

I've got a bare-minimum Erlang port driver:

erl_driver_bridge.c -> erl_driver_bridge.dll

#define __WIN32__

#include "erl_driver.h"

typedef struct {
    ErlDrvPort port;
} erl_driver_bridge_data;

static ErlDrvData bridge_start(ErlDrvPort port, char *buff) {
    erl_driver_bridge_data* d =
        (erl_driver_bridge_data*)driver_alloc(sizeof(erl_driver_bridge_data));
    d->port = port;
    return (ErlDrvData)d;
}

static void bridge_stop(ErlDrvData data) {
    driver_free((char*)data);
}

static void bridge_output(ErlDrvData data, char *buff, int bufflen) {
    erl_driver_bridge_data* d = (erl_driver_bridge_data*)data;
}

ErlDrvEntry erl_driver_bridge_entry = {
    NULL,               /* F_PTR init, N/A */
    bridge_start,       /* L_PTR start, called when port is opened */
    bridge_stop,        /* F_PTR stop, called when port is closed */
    bridge_output,      /* F_PTR output, called when erlang has sent */
    NULL,               /* F_PTR ready_input */
    NULL,               /* F_PTR ready_output */
    "erl_driver_bridge", /* char *driver_name, the argument to open_port */
    NULL,               /* F_PTR finish, called when unloaded */
    NULL,               /* Not used */
    NULL,               /* F_PTR control, port_command callback */
    NULL,               /* F_PTR timeout, reserved */
    NULL,               /* F_PTR outputv, reserved */
    NULL,               /* F_PTR ready_async */
    NULL,               /* F_PTR flush */
    NULL,               /* F_PTR call */
    NULL,               /* F_PTR event */
    ERL_DRV_EXTENDED_MARKER,
    ERL_DRV_EXTENDED_MAJOR_VERSION,
    ERL_DRV_EXTENDED_MINOR_VERSION,
    0,
    NULL,               /* Reserved -- Used by emulator internally */
    NULL,               /* F_PTR process_exit */
};

DRIVER_INIT(erl_driver_bridge) {
    return &erl_driver_bridge_entry;
}

Then I try to load it in Erlang:

case erl_ddll:load_driver(".", erl_driver_bridge) of
    ok -> ok;
    {error, Error} -> erl_ddll:format_error(Error)
end.

Which produces:

The specified module could not be found.

I've checked that the driver exists in the current directory and even specified the full path, but Erlang still doesn't see it. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(3

梦里寻她 2024-08-10 03:17:13

在 Windows 上,文件的扩展名应该是 ddl,而不是 dll

On Windows, the extension of the file should be ddl, not dll ?

像你 2024-08-10 03:17:13

您可能应该使用“file:get_cwd”首先获取当前工作目录,然后附加您的路径。

也很方便,但可能与您当前的问题无关:您检查过 Erlang 模拟器使用的代码路径吗?使用函数 'code:get_path' (http://www.erlang.org/doc /man/code.html)来检查搜索路径。您可以使用“code:add_path”方便地插入路径。

You should probably use 'file:get_cwd' to get the current working directory first and append your path next.

Also handy but probably unrelated to your current question: have you checked the code path that the Erlang emulator uses? Use the function 'code:get_path' (http://www.erlang.org/doc/man/code.html) to inspect the search path. You can use 'code:add_path' to insert paths conveniently.

习ぎ惯性依靠 2024-08-10 03:17:13

将你的与我不久前破解的最低限度进行比较。可能有帮助,可能没有帮助...

  • 我还包含了 ei.h

  • 我声明了 ErlDrvEntry erl_driver_bridge_entry 静态

Comparing yours to my bare-minimum one, which I hacked a while ago. Might help, might not help...

  • I also included ei.h

  • I declared ErlDrvEntry erl_driver_bridge_entry static

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文