1

I have use erlang 21 version. When call "erl", it will run user's .erlang file for loading library's ebin file.

When running the following script by escript, it will not call.

#!/usr/bin/env escript
%% -*- erlang -*-
%%! -sname factorial -mnesia debug verbose
main([String]) ->
    try
    % io:format("~p",[lager_app:module_info()]),
    io:format("aaaa"),
        N = list_to_integer(String),
        F = fac(N),
        io:format("factorial ~w = ~w\n", [N,F])
    catch
        _:_ ->
            usage()
    end;
main(_) ->
    usage().

usage() ->
    io:format("aaaa\n~p",[lager_app:module_info()]),
    io:format("usage: factorial integer\n"),
    halt(1).

fac(0) -> 1;
fac(N) -> N * fac(N-1).

The error message is as follows:

yuchen@chenyu-Vostro-5468:~/a$ ./factorial
escript: exception error: undefined function lager_app:module_info/0
Chen Yu
  • 3,955
  • 1
  • 24
  • 51
  • I think you need to add `-pa ` to your script pointing to the folder with lager inside of it. See https://www.erlang.org/doc/man/erl.html – 2240 Mar 16 '23 at 08:55
  • Does this answer your question? [Erlang - undefined function](https://stackoverflow.com/questions/12585612/erlang-undefined-function) – 2240 Apr 03 '23 at 07:16

1 Answers1

1

To resolve the error about ".erlang.cookie must be accessible by owner only" that is mentioned in the title of this post you need to change the cookie permissions to 600. You can use the following command: chmod 600 ~/.erlang.cookie

The other error message shown in the body of your post about "undefined function lager_app:module_info/0" means that you don't have lager setup properly. If you comment out the line with lager_app you should get past that error.

Here are the docs on setting up lager. It looks like you will need to configure it in rebar.config and app.config and also call lager:start() before using it.

I hope this helps.

dynamicbutter
  • 311
  • 1
  • 5