Erlang Can';“未找到包含库”;兔子“普通/包括/兔子.hrl”;牛仔装
尝试在OSX下的Erlang中运行RabbitMQ的教程示例,但失败并显示以下消息:Erlang Can';“未找到包含库”;兔子“普通/包括/兔子.hrl”;牛仔装,erlang,cowboy,Erlang,Cowboy,尝试在OSX下的Erlang中运行RabbitMQ的教程示例,但失败并显示以下消息: ./send.erl:20: can't find include lib "rabbit_common/include/rabbit.hrl" ./send.erl:21: can't find include lib "rabbit_common/include/rabbit_framing.hrl" escript: There were compilation errors. amqp_example
./send.erl:20: can't find include lib "rabbit_common/include/rabbit.hrl"
./send.erl:21: can't find include lib "rabbit_common/include/rabbit_framing.hrl"
escript: There were compilation errors.
amqp_example.erl:
-module(amqp_example).
-include("amqp_client.hrl").
-compile([export_all]).
test() ->
%% Start a network connection
{ok, Connection} = amqp_connection:start(#amqp_params_network{}),
%% Open a channel on the connection
{ok, Channel} = amqp_connection:open_channel(Connection),
%% Declare a queue
#'queue.declare_ok'{queue = Q}
= amqp_channel:call(Channel, #'queue.declare'{}),
%% Publish a message
Payload = <<"foobar">>,
Publish = #'basic.publish'{exchange = <<>>, routing_key = Q},
amqp_channel:cast(Channel, Publish, #amqp_msg{payload = Payload}),
%% Get the message back from the queue
Get = #'basic.get'{queue = Q},
{#'basic.get_ok'{delivery_tag = Tag}, Content}
= amqp_channel:call(Channel, Get),
%% Do something with the message payload
%% (some work here)
%% Ack the message
amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),
%% Close the channel
amqp_channel:close(Channel),
%% Close the connection
amqp_connection:close(Connection),
ok.
-模块(amqp_示例)。
-包括(“amqp_client.hrl”)。
-编译([export_all])。
测试()->
%%启动网络连接
{ok,Connection}=amqp_Connection:start(#amqp_params_network{}),
%%打开连接上的频道
{ok,Channel}=amqp_连接:打开_通道(连接),
%%声明队列
#'queue.declare_ok'{queue=Q}
=amqp_channel:call(channel,#'queue.declare'{}),
%%发布消息
有效载荷=,
Publish=#'basic.Publish'{exchange=,routing_key=Q},
amqp_频道:cast(频道,发布,#amqp_msg{payload=payload}),
%%从队列中获取消息
Get=#basic.Get'{queue=Q},
{#'basic.get_ok'{delivery_tag=tag},Content}
=amqp_信道:呼叫(信道,获取),
%%对消息负载执行一些操作
%%(这里有些工作)
%%确认消息
amqp_channel:cast(channel,#'basic.ack'{delivery_tag=tag}),
%%关闭频道
amqp_通道:关闭(通道),
%%关闭连接
amqp_连接:关闭(连接),
好啊
请帮我解决这个问题。谢谢 Erlang有宏
include_lib
,它可以在路径中搜索库,而且很方便,因为您不必指定库的版本-它会自动使用最新版本。因此,与其
-include("rabbit_common-3.3.5/include/rabbit.hrl").
你可以写:
-include_lib("rabbit_common/include/rabbit.hrl").
因此,在您的情况下,您必须确保文件rabbit\u common-[version]/include/rabbit.hrl
位于ERL\u LIBS
路径中。在中,他们希望您从中下载这些文件并按如下方式解包:
unzip -d deps deps/amqp_client.ez
unzip -d deps deps/rabbit_common.ez
这些解包命令在OSX上不起作用,因为unzip只适用于.zip文件。所以这可能是你的问题。尝试使用另一个应用程序解包,并仔细检查文件是否存在。在编译和运行示例之前,不要忘记添加ERL_LIBS=deps
:
ERL_LIBS=deps erlc -o ebin amqp_example.erl
ERL_LIBS=deps erl -pa ebin
您好@tkowal,我如何在ERL_LIBS路径中添加文件rabbit_common-[version]/include/rabbit.hrl?您必须在命令前添加deps目录。然后,如果您解包了
deps/rabbit\u common-3.3.5/include/rabbit.hrl
文件,它就会找到它。感谢您的帮助@tkowal,它现在正在工作。:)