2
votes

Trying to run tutorial samples for RabbitMQ in Erlang under OSX but it fails with the following message:

./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.

Please help me to fix this problem. Thank!!!

1

1 Answers

3
votes

Erlang has macro include_lib, which can search for libraries in path and is convenient, because you don't have to specify version of library - it automatically uses newest version. So, instead of

-include("rabbit_common-3.3.5/include/rabbit.hrl").

you can just write:

-include_lib("rabbit_common/include/rabbit.hrl").

So, in your case, you have to make sure, that file rabbit_common-[version]/include/rabbit.hrl is in ERL_LIBS path. In the tutorial, you are using, they want you to download those files from here and unpack them like this:

unzip -d deps deps/amqp_client.ez
unzip -d deps deps/rabbit_common.ez

Those unpacking commands do not work on OS X, because unzip works only with .zip files. So this might be your problem. Try using another application to unpack them and double check, that the file is there. Don't forget to add ERL_LIBS=deps before compiling and running the example:

ERL_LIBS=deps erlc -o ebin amqp_example.erl
ERL_LIBS=deps erl -pa ebin