我正在用protobuffs(basho)编写一个erlang牧场应用程序,并且我在开始时包含了test_pb.hrl,(include("test_pb.hrl")
)。但当我制作应用程序并运行时,它收到错误:
{'module could not be loaded',
[{protobuffs,next_field_num,[<<10,5,116,101,115,116,49>>],[]},
{test_pb,decode,3,[{file,"src/test_pb.erl"},{line,143}]},
{test_pb,decode,2,[{file,"src/test_pb.erl"},{line,138}]},
{reverse_protocol,handle_info,2,
[{file,"src/reverse_protocol.erl"},{line,47}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,604}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}
和第47行是:Msgdata = test_pb:decode_test(Data),
整个源文件是: ` %%您可以随意使用,重复使用和滥用此文件中的代码。
-module(reverse_protocol).
-behaviour(gen_server).
-behaviour(ranch_protocol).
-import(lists, [reverse/1]).
-include("test_pb.hrl").
%% API.
-export([start_link/4]).
%% gen_server.
-export([init/1]).
-export([init/4]).
-export([handle_call/3]).
-export([handle_cast/2]).
-export([handle_info/2]).
-export([terminate/2]).
-export([code_change/3]).
-define(TIMEOUT, 5000).
-record(state, {socket, transport}).
%% API.
start_link(Ref, Socket, Transport, Opts) ->
proc_lib:start_link(?MODULE, init, [Ref, Socket, Transport, Opts]).
%% gen_server.
%% This function is never called. We only define it so that
%% we can use the -behaviour(gen_server) attribute.
init([]) -> {ok, undefined}.
init(Ref, Socket, Transport, _Opts = []) ->
ok = proc_lib:init_ack({ok, self()}),
ok = ranch:accept_ack(Ref),
ok = Transport:setopts(Socket, [{active, once}]),
gen_server:enter_loop(?MODULE, [],
#state{socket=Socket, transport=Transport},
?TIMEOUT).
handle_info({tcp, Socket, Data}, State=#state{
socket=Socket, transport=Transport}) ->
Transport:setopts(Socket, [{active, once}]),
io:format("receive data ~p~n", [Data]),
Msgdata = test_pb:decode_test(Data),
io:format("receive data unpack ~p~n", [Msgdata]),
Transport:send(Socket, reverse_binary(Data)),
{noreply, State, ?TIMEOUT};
handle_info({tcp_closed, _Socket}, State) ->
{stop, normal, State};
handle_info({tcp_error, _, Reason}, State) ->
{stop, Reason, State};
handle_info(timeout, State) ->
{stop, normal, State};
handle_info(_Info, State) ->
{stop, normal, State}.
handle_call(_Request, _From, State) ->
{reply, ok, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%% Internal.
reverse_binary(B) when is_binary(B) ->
[list_to_binary(lists:reverse(binary_to_list(
binary:part(B, {0, byte_size(B)-2})
))), "\r\n"].
`
答案 0 :(得分:1)
虚拟机无法找到protobuffs
模块。如果您在deps文件夹中有protobuffs应用程序,请尝试将-pz deps/*/ebin
添加到启动选项中。
答案 1 :(得分:0)
如果您不确定模块是否已加载,请在erlang shell中尝试XXXX:module_info()。如果错误,则不在路径中并尝试使用代码:paths(&#34; xxxxxx / ebin&#34;)来添加它。