user5836035
user5836035

Reputation:

Erlang importing modules from other directories

I've done a module "parser" wich is located in "./local/lib/parser.erl". Is it possible to import the module from "./local/main.erl"?

I have tried to use in my main module:

-import("./lib/parser", [functions]).

-import('./lib/parser', [functions]).

-import(lib.parser, [functions]).

And none of them is giving to me the correct compilation. I have searched in Erlang's documentation but could not found what I was looking for.

Thanks for your answers.

Upvotes: 7

Views: 3975

Answers (1)

BlackMamba
BlackMamba

Reputation: 10254

-import(Module,Functions). Imported functions. Can be called the same way as local functions, that is, without any module prefix.

Module, an atom, specifies which module to import functions from. Functions is a list similar as for export.

Your erlang source file in ./local/lib/parser.erl, but after you compile this source file, there will be a beam file, your should add the beam file path to your erlang code path.

The right synax is -import('parser', [functions]). But the path of parse.beam shoud be in your erlang code path.

About erlang code path, please read this link:http://erlang.org/doc/man/code.html

Upvotes: 8

Related Questions