【问题标题】:Can't compile a new module in ejabberd无法在 ejabberd 中编译新模块
【发布时间】:2015-02-21 00:39:06
【问题描述】:

我正在尝试为 erlang 中的 ejabberd 编译一个新模块。我正在关注本教程:http://jasonrowe.com/2011/12/30/ejabberd-offline-messages

我正在尝试编译这段代码:

%% name of module must match file name
-module(mod_http_offline).

-author("Earl The Squirrel").

%% Every ejabberd module implements the gen_mod behavior
%% The gen_mod behavior requires two functions: start/2 and stop/1
-behaviour(gen_mod).

%% public methods for this module
-export([start/2, stop/1, create_message/3]).

%% included for writing to ejabberd log file
-include("ejabberd.hrl").

%% ejabberd functions for JID manipulation called jlib.
-include("jlib.hrl").

start(_Host, _Opt) ->
        post_offline_message("testFrom", "testTo", "testBody"),
        ?INFO_MSG("mod_http_offline loading", []),
        ejabberd_hooks:add(offline_message_hook, _Host, ?MODULE, create_message, 50).  



stop (_Host) ->
        ?INFO_MSG("stopping mod_http_offline", []),
        ejabberd_hooks:delete(offline_message_hook, _Host, ?MODULE, create_message, 50).



create_message(_From, _To, Packet) ->
        Type = xml:get_tag_attr_s("type", Packet),
        FromS = xml:get_tag_attr_s("from", Packet),
        ToS = xml:get_tag_attr_s("to", Packet),
        Body = xml:get_path_s(Packet, [{elem, "body"}, cdata]),
        if (Type == "chat") ->
            post_offline_message(FromS, ToS, Body)
        end.



post_offline_message(From, To, Body) ->
        ?INFO_MSG("Posting From ~p To ~p Body ~p~n",[From, To, Body]),
        ?INFO_MSG("post request sent (not really yet)", []).

我已将 jlib.hrl,ejabberd.hrl 添加到我的文件夹中。但是当我尝试编译此代码时,出现以下错误:

jlib.hrl:22: can't find include lib "p1_xml/include/xml.hrl"
mod_http_offline.erl:21: undefined macro 'INFO_MSG/2'
mod_http_offline.erl:27: undefined macro 'INFO_MSG/2'
mod_http_offline.erl:44: undefined macro 'INFO_MSG/2'
jlib.hrl:426: record xmlel undefined
jlib.hrl:466: type xmlel() undefined
mod_http_offline.erl:11: function start/2 undefined
mod_http_offline.erl:11: function stop/1 undefined
mod_http_offline.erl:38: function post_offline_message/3 undefined
mod_http_offline.erl:8: Warning: behaviour gen_mod undefined

我该如何解决这个问题?

我的 Ejabberd 版本:2.1.11

【问题讨论】:

    标签: erlang ejabberd


    【解决方案1】:

    ejabberd 存储库中的 jlib.hrl 文件包含 -include("ns.hrl").(第 21 行)和 -include_lib("p1_xml/include/xml.hrl"). 第 22 行。 include_lib 表示它将在库路径中搜索文件。您可以修改它并在您的目录中添加必要的文件(也许是一个简单的测试解决方案?)但我认为干净的方法是将 tour 文件添加到 ejabberd 应用程序并使用 rebar 编译它。

    【讨论】:

    • 如何运行钢筋?我在 ubuntu 中找不到 rebar 的位置。
    • 如果你从 github [github.com/processone/ejabberd] 克隆 ejabberd,它将附带 rebar 和所有应用程序结构 + 安装说明
    • 我已经安装了ejabberd。但是我不知道如何运行rebar。
    • :o) 我没有安装 ejabberd,但通常你只需要输入 ./rebar compile 或其他命令。 [github.com/rebar/rebar/wiki] 的文档
    • 我想我必须知道 ejabberd 文件的位置。你知道 ejabberd 文件在哪里吗?因为当我下载源代码时,我在目录中看到了钢筋文件。但我不知道这些文件在 ubuntu 中的位置。
    猜你喜欢
    • 2016-01-13
    • 2013-08-14
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 2016-01-12
    • 2016-03-10
    相关资源
    最近更新 更多