14.1 Compilation

Erlang programs must be compiled to object code. The compiler can generate a new file that contains the object code. The current abstract machine, which runs the object code, is called BEAM, therefore the object files get the suffix .beam. The compiler can also generate a binary which can be loaded directly.

The compiler is located in the module compile (see the compile(3) manual page in Compiler).

  1. compile:file(Module)
  2. compile:file(Module, Options)

The Erlang shell understands the command c(Module) which both compiles and loads Module.

There is also a module make, which provides a set of functions similar to the UNIX type Make functions, see the make(3) manual page in Tools.

The compiler can also be accessed from the OS prompt, see the erl(1) manual page in ERTS.

  1. % erl -compile Module1...ModuleN
  2. % erl -make

The erlc program provides an even better way to compile modules from the shell, see the erlc(1) manual page in ERTS. It understands a number of flags that can be used to define macros, add search paths for include files, and more.

  1. % erlc <flags> File1.erl...FileN.erl