Muja Null
Muja Null

Reputation: 53

Emakefile - custom behaviour undefined

My test project is structured this way:

./Emakefile:

{"source/*", [debug_info, {outdir, "binary"}]}.

./source/test.erl:

-module(test).
-behaviour(test_behaviour).

./source/test_behaviour.erl:

-module(test_behaviour).
-export([behaviour_info/1]).

behaviour_info(callbacks) -> [];
behaviour_info(_) -> undefined.

When I use the command erl -make in the project directory (.), I get the following output:

Recompile: source/test_behaviour
Recompile: source/test
source/test.erl:2: Warning: behaviour test_behaviour undefined

Why does erl print this warning ? It compiled test_behaviour.erl before test.erl, so I guess it should be able to find test_behaviour.beam in the binary folder.

Upvotes: 5

Views: 1391

Answers (1)

Vinod
Vinod

Reputation: 2243

Behaviors are resolved at the compile time. Hence the Erlang compiler should find the behavior beam file and call the behavior module's behaviour_info/1 function.

Here test_behaviour.beam is not in the code path of the compiler. You can run by calling

erl -pa ebin -make

This solved the problem for me. I tried specifying in Emakefile but with no luck. Could not find the documentation also. Also found that oder of -pa ebin has to be before -make (not sure why though).

Upvotes: 4

Related Questions