Home > Mobile >  erlang - rest api example and problem with compilation
erlang - rest api example and problem with compilation

Time:10-27

I am trying to use this project for educational purposes: https://github.com/dronowar/erlang_rest_api

But problem with code compilation and make run-local:

erl -config config/sys -pa ./ebin -pa ./deps/*/ebin -sname erl@localhost -s erl -s sync
Erlang/OTP 24 [erts-12.1.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]

{"init terminating in do_boot",{undef,[{erl,start,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ({undef,[{erl,start,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]})

Crash dump is being written to: erl_crash.dump...done
make: *** [run-local] Error 1

CodePudding user response:

Honestly it could be a lot of things. The project is 3-4 years old, all the deps are unpinned i.e. will fetch the newest versions.

It might be worth pinning them back to something that was contemporary to the project.

With Erlang 24, rebar3 was complaining due to erlang:get_stacktrace()being removed, meaning deps were not being compiled.

I tried to run make using Erlang 20, and ended up with a failure due to a missing C compiler (I'm on Windows) but it certainly got further in the build/compile process. So perhaps downgrade Erlang to try.

CodePudding user response:

It seems like the Makefile is out of sync with modern Rebar3 versions. I changed the run-local target to say:

run-local:
    erl -config config/sys -pa _build/default/lib/*/ebin -sname $(APPNAME)@localhost -s $(APPNAME) -s sync

(Note that the second line starts with a tab character, not a run of spaces.)

With that change, the node starts for me, and complains about not being able to connect to Postgres.


So how would you know that? The error you get is {undef,[{erl,start,[],[]}. That means that it tried to call the function start in the module erl with zero arguments (the argument list is empty, []), but there is no such function, either because the module doesn't have such a function, or because the entire module couldn't be loaded.

So I searched for the compiled module, erl.beam:

$ find . -name erl.beam
./_build/default/lib/erl/ebin/erl.beam

These days Rebar3 likes to put compiled files into the _build subdirectory, but when erlang_rest_api was written, it apparently just used the ebin subdirectory. The -pa arguments to erl indicate the module search path, so let's just add the correct directories there, and remove -pa ./ebin -pa ./deps/*/ebin which are now unused.

  • Related