I am having a similar problem as here for running an rebar app
Basically, I want to run the demo code from: https://github.com/hukl/fancyapi
When I am in the root directory, and I do:
→ erl [...] -pa ebin -pa deps/*/ebin
Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false] [dtrace]
Eshell V5.9.2 (abort with ^G)
1> application
1> .
application
2> application:start(fancyapi).
{error,{"no such file or directory","fancyapi.app"}}
3> application:start("fancyapi").
{error,{bad_application,"fancyapi"}}
4>
How would ERL find the fancyapi code?
[g#dev1 ~/work]$ git clone git://github.com/hukl/fancyapi.git
Cloning into 'fancyapi'...
remote: Counting objects: 12, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 12 (delta 0), reused 12 (delta 0)
Receiving objects: 100% (12/12), done.
[g#dev1 ~/work]$ cd fancyapi/
[g#dev1 ~/work/fancyapi]$ rebar get-deps
==> fancyapi (get-deps)
Pulling etest from {git,"git://github.com/wooga/etest.git"}
Cloning into 'etest'...
Pulling etest_http from {git,"git://github.com/wooga/etest_http.git"}
Cloning into 'etest_http'...
Pulling elli from {git,"git://github.com/knutin/elli.git"}
Cloning into 'elli'...
==> etest (get-deps)
==> etest_http (get-deps)
Pulling jiffy from {git,"git://github.com/davisp/jiffy.git","HEAD"}
Cloning into 'jiffy'...
==> jiffy (get-deps)
==> elli (get-deps)
[g#dev1 ~/work/fancyapi]$ rebar compile
==> etest (compile)
Compiled src/etest_runner.erl
==> jiffy (compile)
Compiled test/jiffy_tests.erl
Compiled test/util.erl
Compiled src/jiffy_utf8.erl
Compiled src/jiffy.erl
Compiled test/etap.erl
Compiling c_src/decoder.c
Compiling c_src/encoder.c
Compiling c_src/jiffy.c
Compiling c_src/utf8.c
Compiling c_src/util.c
==> etest_http (compile)
Compiled src/etest_http.erl
Compiled src/etest_http_json.erl
Compiled test/etest_http_test.erl
==> elli (compile)
Compiled src/elli_handler.erl
Compiled src/elli_middleware_compress.erl
Compiled src/elli_example_middleware.erl
Compiled src/elli_middleware.erl
Compiled src/elli_util.erl
Compiled src/elli_request.erl
Compiled src/elli.erl
Compiled src/elli_test.erl
Compiled src/elli_example_callback.erl
Compiled src/elli_http.erl
==> fancyapi (compile)
Compiled src/fancyapi_app.erl
Compiled src/fancyapi_callback.erl
Compiled src/fancyapi_sup.erl
Compiled test/my_fancy_test.erl
[g#dev1 ~/work/fancyapi]$ erl -pa ebin -pa ebin deps/*/ebin
Erlang R15B03 (erts-5.9.3.1) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3.1 (abort with ^G)
1> application:start(fancyapi).
ok
Related
I am studying the upgrade of erlang applications based on this article.
But there is some problem when I execute rebar3 relup:
Option --relname is missing
hello#centos7-dev:~/relapp1 ((1.0.12))$ rebar3 relup
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling relapp
Solving Release relapp-1.0.12Resolved relapp-1.0.12release: relapp-1.0.12
erts: 13.0.4
goals:
relapp
parse_trans
sasl
applications:
{kernel,"8.4.2"}
{stdlib,"4.0.1"}
{syntax_tools,"3.0"}
{parse_trans,"3.0.0"}
{relapp,"1.0.12"}
{sasl,"4.2"}
......
....relapp1/_build/default/rel/relapp/lib/sasl-4.2/ebin/sasl.apprelease start script createdRelease successfully assembled:
_build/default/rel/relapp===> Option --relname is missing
The environments are as follows:
erlang
Erlang/OTP 25 [erts-13.0.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]
Eshell V13.0.4 (abort with ^G)
rebar3
rebar 3.20.0 on Erlang/OTP 25 Erts 13.0.4
After many times of retry and experiment, I found it in this article.
Hot code reloading with Erlang and Rebar3
The answer is such as:
rebar3 relup -n nine9s -v "0.2.0" -u "0.1.0"
However, there are some issues which need attention.
The rebar.config file
You should replace the default options {mode, dev} with {dev_mode, false}
the *.appup.src
You cannot include the point_of_no_return option in this file, otherwise there will be some problem such as:
No release upgrade script entry for xxxx-0.2.0 to xxxx-0.1.0 in file
I cannot import and therefore cannot call a function of another module in my 'main' module. I am an Erlang newbie. Below is my 'main' module.
-module('Sysmod').
-author("pato").
%% API
-export([ hello_world/0,sayGoodNight/0]).
-import('Goodnight',[sayGoodNight/0]).
hello_world()->
io:fwrite("Hello World\n").
Below is the other module which is being imported.
-module('Goodnight').
-author("pato").
%% API
-export([sayGoodNight/0]).
sayGoodNight() ->
io:format("Good night world\n").
I cannot even compile my 'main' module(Sysmod), once I export the imported function, as it throws an undefined shell command error. It compiles when I have imported the module and function, but cannot execute the function and it throws a undefined function error. I have checked out [this answer]1 and also looked at [erlang man pages on code server]2.
In addition, I managed to add_path of the Erlang Decimal library successfully as below attempting my app to talk to an external library.
12> code:add_path("/home/pato/IdeaProjects/AdminConsole/erlang-decimal-master/ebin"). true
But cannot run any Decimal function successfully as shown below.
decimal:add("1.3", "1.07").** exception error: undefined function decimal:add/2
In short, the first method,(I know its not recommended due to unreadability) of intermodule communication using import is not working. As I looked for a solution, I realized the add-path only works with modules that have an ebin directory.
I am stuck. How do I make my modules talk to each other including an external library added successfully by add_path? I have heard of exref, i cannot grasp the Erlang man pages. I need someone to explain it to me like a five year old. Thank you.
I am an Erlang newbie
Don't use import. No one else does. It's bad programming practice. Instead, call functions by their fully qualified names, i.e. moduleName:functionName
throws a undefined function error
You didn't compile the module you are trying to import. Also, you can't export a function that is not defined within a module.
Here's an example:
~/erlang_programs$ mkdir test1
~/erlang_programs$ cd test1
~/erlang_programs/test1$ m a.erl %%creates a.erl
~/erlang_programs/test1$ cat a.erl
-module(a).
-compile(export_all).
go()->
b:hello().
~/erlang_programs/test1$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V9.3 (abort with ^G)
1> c(a).
a.erl:2: Warning: export_all flag enabled - all functions will be exported
{ok,a}
2> a:go().
** exception error: undefined function b:hello/0
3>
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
~/erlang_programs/test1$ mkdir test2
~/erlang_programs/test1$ cd test2
~/erlang_programs/test1/test2$ m b.erl %%creates b.erl
~/erlang_programs/test1$ cat b.erl
-module(b).
-compile(export_all).
hello() ->
io:format("hello~n").
~/erlang_programs/test1/test2$ erlc b.erl
b.erl:2: Warning: export_all flag enabled - all functions will be exported
~/erlang_programs/test1/test2$ ls
b.beam b.erl
~/erlang_programs/test1/test2$ cd ..
~/erlang_programs/test1$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V9.3 (abort with ^G)
1> c(a).
a.erl:2: Warning: export_all flag enabled - all functions will be exported
{ok,a}
2> a:go().
** exception error: undefined function b:hello/0
3> code:add_path("./test2").
true
4> a:go().
hello
ok
I took the master branch for riak-erlang-client and called make
./rebar get-deps
==> meck (get-deps)
==> protobuffs (get-deps)
==> hamcrest (get-deps)
==> riak_pb (get-deps)
==> riak-erlang-client (get-deps)
./rebar compile
==> meck (pre_compile)
==> meck (compile)
==> protobuffs (pre_compile)
==> protobuffs (compile)
==> hamcrest (pre_compile)
==> hamcrest (compile)
==> hamcrest (post_compile)
==> riak_pb (pre_compile)
==> riak_pb (compile)
==> riak-erlang-client (compile)
raghuveer#ubuntu:~/erlang-git/riak-erlang-client$ erl -pa $PATH_TO_RIAKC/ebin $PATH_TO_RIAKC/deps/*/ebin
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
Eshell V7.3 (abort with ^G)
1> code:which(riakc_pb_socket).
non_existing
Also tried
make clean && make all
build went fine, but when i call
./rebar install
i see cannot be run on erlang-java-client directory. Fine so to check if the installation is already done i ran below :
/riak-erlang-client$ erl -pa $PATH_TO_RIAKC/ebin $PATH_TO_RIAKC/deps/*/ebin
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
Eshell V7.3 (abort with ^G)
1> code:which(riakc_pb_socket).
non_existing
What can i do to fix this error. Thanks in advance.
From the ~/erlang-git/riak-erlang-client directory, run this instead:
erl -pa ./ebin ./deps/*/ebin
The examples use the $PATH_TO_RIAKC environment variable to demonstrate that you must set this variable if you run erl from another location. Since the .beam files for the Erlang client and its dependencies are available, you don't need this env variable to be set.
(Newbie here) I am having an error when trying to run ranch example.
Via rebar I created application and node (please see on github).
But when I am trying to build and run it I am getting undef ranch,start_listener.
Please see full console output:
$ rebar get-deps compile generate && sh rel/reverse/bin/reverse console
WARN: Expected reverse/deps/ranch to be an app dir (containing ebin/*.app), but no .app found.
==> rel (get-deps)
==> reverse (get-deps)
WARN: Expected reverse/deps/ranch to be an app dir (containing ebin/*.app), but no .app found.
Pulling ranch from {git,"git#github.com:ninenines/ranch.git",{tag,"1.1.0"}}
Cloning into 'ranch'...
==> ranch (get-deps)
==> ranch (compile)
Compiled src/ranch_transport.erl
Compiled src/ranch_sup.erl
Compiled src/ranch_ssl.erl
Compiled src/ranch_tcp.erl
Compiled src/ranch_protocol.erl
Compiled src/ranch_listener_sup.erl
Compiled src/ranch_app.erl
Compiled src/ranch_acceptors_sup.erl
Compiled src/ranch_acceptor.erl
Compiled src/ranch_server.erl
Compiled src/ranch.erl
Compiled src/ranch_conns_sup.erl
==> rel (compile)
==> reverse (compile)
Compiled src/reverse_sup.erl
Compiled src/reverse_app.erl
Compiled src/reverse_protocol.erl
==> rel (generate)
WARN: 'generate' command does not apply to directory reverse
Exec: reverse/rel/reverse/erts-6.3/bin/erlexec -boot reverse/rel/reverse/releases/1/reverse -mode embedded -config reverse/rel/reverse/releases/1/sys.config -args_file reverse/rel/reverse/releases/1/vm.args -- console
Root: reverse/rel/reverse
Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V6.3 (abort with ^G)
(reverse#127.0.0.1)1>
=INFO REPORT==== 30-Dec-2014::22:47:08 ===
application: reverse
exited: {bad_return,
{{reverse_app,start,[normal,[]]},
{'EXIT',
{undef,
[{ranch,start_listener,
[reverse,10,ranch_tcp,
[{port,5555}],
reverse_protocol,[]],
[]},
{reverse_app,start,2,
[{file,"src/reverse_app.erl"},{line,13}]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,272}]}]}}}}
type: permanent
{"Kernel pid terminated",application_controller,"{application_start_failure,reverse,{bad_return,{{reverse_app,start,[normal,[]]},{'EXIT',{undef,[{ranch,start_listener,[reverse,10,ranch_tcp,[{port,5555}],reverse_protocol,[]],[]},{reverse_app,start,2,[{file,\"src/reverse_app.erl\"},{line,13}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,272}]}]}}}}}"}
Crash dump was written to: erl_crash.dump
I am not sure I correctly added ranch to reltool.config (please see on github). But If I remove deps from libs_dir path I will get rebar generate error Application version clash. Multiple directories contain version ....
UPDATE if I remove failing call and run it, application:which_applications(). gives me {ranch,[],[]} as one of the running ones.
UPDATE versions
$ erl
Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
$ rebar --version
rebar 2.5.1 17 20141223_141030 git 2.5.1-84-gdd9125e
What I am doing wrong?
Thanks in advance!
In the reltool.config, remove the ebin directory from the path to Ranch:
{app, ranch, [{mod_cond, app}, {incl_cond, include}, {lib_dir, "../deps/ranch/"}]}
If you have lots of dependencies it's more convenient to do:
{lib_dirs, ["../deps"]}
instead of having a separate {app, <dep_name>, [...]} for each dependency.
The Application version clash. Multiple directories contain version XXX error indicates that the Ranch application is already installed, probably in the Erlang lib directory, creating conflicts with the deps version downloaded by Rebar.
I followed the instructions here, to the letter. I then ran the instruction to create an application project structure, and got the following error.
$ ./rebar create-app appid=myapp
Uncaught error in rebar_core: {'EXIT',
{undef,
[{crypto,start,[]},
{rebar_core,run,1},
{rebar,main,1},
{escript,run,2},
{escript,start,1},
{init,start_it,1},
{init,start_em,1}]}}
Any ideas what I'm doing wrong?
It looks like your Erlang was compiled without OpenSSL (the crypto module). crypto is required for many (most?) Erlang applications. You'll need to get a version of Erlang with a working crypto module, and then you shouldn't have any problems like this.
A clarification to YOUR ARGUMENT IS VALID's answer (adding as an answer because the comment is too short).
It may be that Erlang was compiled properly but the OpenSSL libraries are not visible to Erlang, so the crypto server can't be started. I compiled Erlang on Solaris 10 and it didn't complain about OpenSSL not being installed. In fact, it compiled crypto and installed it in: /usr/local/lib/erlang/lib/crypto-2.2/
But Rebar still wasn't working. It's easy to check if the problem is indeed with the crypto module.
Open Erlang shell and type crypto:start(). This was happening on my system:
bash-3.2# erl
Erlang R15B03 (erts-5.9.3.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3.1 (abort with ^G)
1> crypto:start().
** exception error: undefined function crypto:start/0
2>
=ERROR REPORT==== 8-Feb-2013::15:28:43 ===
Unable to load crypto library. Failed with error:
"load_failed, Failed to load NIF library: 'ld.so.1: beam.smp: fatal: relocation error: file /usr/local/lib/erlang/lib/crypto-2.2/priv/lib/crypto.so: symbol DES_ede3_cfb_encrypt: referenced symbol not found'"
OpenSSL might not be installed on this system.
=ERROR REPORT==== 8-Feb-2013::15:28:43 ===
The on_load function for module crypto returned {error,
{load_failed,
"Failed to load NIF library: 'ld.so.1: beam.smp: fatal: relocation error: file /usr/local/lib/erlang/lib/crypto-2.2/priv/lib/crypto.so: symbol DES_ede3_cfb_encrypt: referenced symbol not found'"}}
If OpenSSL is installed in a non-standard location, as it is the case when using OpenCSW to install OpenSSL on Solaris 10, it is easy to fix the problem by adding the library path to the environment variable. For example on Solaris 10 to /etc/profile:
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/csw/lib
export LD_LIBRARY_PATH
Then log-out and log-in or re-load the bash environment, for example like this:
bash-3.2# . /etc/profile
Result:
bash-3.2# erl
Erlang R15B03 (erts-5.9.3.1) [source] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3.1 (abort with ^G)
1> crypto:start().
ok
I'd recommend using precompiled Erlang which is available from Erlang Solutions: https://www.erlang-solutions.com/downloads/download-erlang-otp
There's one for Windows too.
Getting this error when running make command:
root#hs:/var/www/html/ejabberd-master# make
rm -rf deps/.got
rm -rf deps/.built
/usr/local/lib/erlang/bin/escript rebar get-deps && :> deps/.got
Uncaught error in rebar_core: {'EXIT',
{undef,
[{crypto,start,[],[]},
{rebar,run_aux,2,
[{file,"src/rebar.erl"},{line,163}]},
{rebar,main,1,
[{file,"src/rebar.erl"},{line,58}]},
{escript,run,2,
[{file,"escript.erl"},{line,757}]},
{escript,start,1,
[{file,"escript.erl"},{line,277}]},
{init,start_it,1,[]},
{init,start_em,1,[]}]}}
make: *** [deps/.got] Error 1
The erlang details are:
root#hs:/home/node# erl
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async- threads:10] [hipe] [kernel-poll:false]
Eshell V7.0 (abort with ^G)
1> crypto:start()
1>
Seems like crypto not working, as the command gives "Ok" or "exception error".
Help needed.
Thanks for the answer Ivan. But it seems I figured out the issue:
The ubuntu auto updates were turned off and the dependencies were not installed while compiling erlang (e.g. libssh-dev). Once the auto update was turned on it compiled and make command ran fine.