soft-developer
soft-developer

Reputation: 41

How i compile and run erlang program?

i have

  1. freebsd 10
  2. folder /usr/home/ec2-user/ezmq with files from https://github.com/zeromq/ezmq
  3. installed erlang

then i:

  1. in command line run - erl
  2. in erl

    c("/usr/home/ec2-user/ezmq/examples/hwclient.erl").

    c("/usr/home/ec2-user/ezmq/examples/hwserver.erl").

  3. hwserver:main().

  4. hwclient:main().

and have error

exception error: undefined function ezmq:start/1 in function hwserver:main/0 (/usr/home/ec2-user/ezmq/examples/hwserver.erl, line 14)

and have error

exception error: undefined function ezmq:start/1 in function hwclient:main/0 (/usr/home/ec2-user/ezmq/examples/hwclient.erl, line 14)

how i compile and run

this https://github.com/zeromq/ezmq/blob/master/examples/hwclient.erl + hwserver.erl

examples?

and i have error

** exception exit: {{undef,[{gen_listener_tcp,start_link,
                                              [ezmq_tcp_socket, 
                                               [<0.49.0>,<<>>,5555,
                                                [binary,inet,
                                                 {active,false},
                                                 {send_timeout,5000},
                                                 {backlog,10},
                                                 {nodelay,true},
                                                 {packet,raw},
                                                 {reuseaddr,true}]],
                                               []],
                                              []},
                            {ezmq,handle_call,3,[{file,"src/ezmq.erl"},{line,238}]},
                            {gen_server,handle_msg,5,
                                        [{file,"gen_server.erl"},{line,585}]},
                            {proc_lib,init_p_do_apply,3,
                                      [{file,"proc_lib.erl"},{line,239}]}]},
                    {gen_server,call,[<0.49.0>,{bind,tcp,5555,[]}]}}
     in function  gen_server:call/2 (gen_server.erl, line 180)
     in call from hwserver:main/0 (/usr/home/ec2-user/ezmq/examples/hwserver.erl, line 15)

Upvotes: 1

Views: 9227

Answers (1)

kjw0188
kjw0188

Reputation: 3685

This project uses rebar, so try this:

  1. Download it from here: https://github.com/rebar/rebar/wiki/rebar
  2. Make it executable
  3. Compile: ./rebar compile
  4. Open two terminals
  5. In terminal 1, run: erl -pa ebin -pa /deps/gen_listener_tcp/ebin The -pa option tells the vm where to load beam files from.

    1. In the erlang shell, run:

      c("examples/hwserver") hwserver:main().

  6. In terminal 2, run: erl -pa ebin -pa /deps/gen_listener_tcp/ebin

    1. In the erlang shell, run:

      c("examples/hwclient") hwclient:main().

You should see a bunch of output.

The make file seems to require putting rebar in your path. Once you do that, you can try the make targets.

Upvotes: 4

Related Questions