简体   繁体   中英

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

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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM