我正在尝试在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

最佳答案

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

关于erlang - 无法在ejabberd中编译新模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27610733/

10-13 01:12