rama
rama

Reputation: 1

Generate .beam file for imported module

I'm learning erlnag and have a small doubt regarding '.beam' file creation. For example I have helloworld.erl and top.erl files and helloworld.erl is imported in top.erl.

top.erl:

-module(top).
-import(helloworld, [start/0]).
-export([main/0]).

main() ->
  io:fwrite("hello\n"),
  start().

helloworld.erl

-module(helloworld).
-export([start/0]).

start() ->
  io:fwrite("hello world\n").

Then compiling top.erl using "erlc top.erl".Then, it is creating only top.beam file but not creating helloworld.beam file.

But when we see in case of python and java, object files will be generate for the imported file also while compiling importing file.

is this the behavior(i.e not creating .beam file for imported file) of 'erlang' or am i understood wrong?

(or)

Please explain the process to get the '.beam' files for imported one also while running importing module.

Thanks..

Upvotes: 0

Views: 664

Answers (2)

7stud
7stud

Reputation: 48589

Please explain the process to get the '.beam' files for imported one also while running importing module.

There is none. Furthermore, no one who writes Erlang uses -import for modules because it confuses the reader of your code by obfuscating where in fact the function you called is defined. Normally, when you call a function using the syntax start(), that means the function is defined in the module where it is called, and when a function is defined in another module, you call it with the syntax helloworld:start(), which informs the reader of your code that they can examine the helloworld module to read the definition of the start() function.

But when we see in case of python and java, object files will be generate for the imported file also while compiling importing file.

Erlang's -import doesn't work that way.

Upvotes: 0

legoscia
legoscia

Reputation: 41527

erlc only compiles the files you ask it to compile. You can compile all files in the current directory with:

erlc *.erl

You might want to use a tool to build your project. One option that's built-in is the make module (not to be confused with the make command line tool). You can run it with:

erl -make

It looks for a configuration file called Emakefile file in the current directory, but if there is none it will just compile all source files in the directory.

Other alternatives are rebar3 and erlang.mk.

Upvotes: 1

Related Questions