itamar
itamar

Reputation: 1940

erlang- how to compile&load external module within a code

I want to compile&load mod.erl from test_mod.erl

i tried to do this:

 -module(mod_test).
 -export([test/0]).   

 test()->
         compile:file(mod),
         mod:start().

but if its not doing the job

Upvotes: 0

Views: 170

Answers (1)

legoscia
legoscia

Reputation: 41528

You can't put expressions on the top level of a module; you need to enclose them in a function, like this:

-module(mod_test).

-export([compile_and_load_mod/0]).

compile_and_load_mod() ->
    compile:file(mod),
    mod:start().

Then you can call mod_test:compile_and_load_mod().

Upvotes: 1

Related Questions