ERLC(1) General Commands Manual ERLC(1)

erlc - Compiler

The erlc program provides a common way to run all compilers in the Erlang system. Depending on the extension of each input file, erlc invokes the appropriate compiler. Regardless of which compiler is used, the same flags are used to provide parameters, such as include paths and output directory.

The current working directory, ".", is not included in the code path when running the compiler. This is to avoid loading Beam files from the current working directory that could potentially be in conflict with the compiler or the Erlang/OTP system used by the compiler.

Compiles one or more files. The files must include the extension, for example, .erl for Erlang source code, or .yrl for Yecc source code. Erlc uses the extension to invoke the correct compiler.

The following flags are supported:

erlc +export_all file.erl
Depending on the platform, the value may need to be quoted if the shell itself interprets certain characters. On Unix, terms containing tuples and lists must be quoted. Terms containing spaces must be quoted on all platforms.

The following flags are useful in special situations, such as rebuilding the OTP system:

The following compilers are supported:

.erl - Erlang source code. It generates a .beam file.
Options -P, -E, and -S are equivalent to +'P', +'E', and +'S', except that it is not necessary to include the single quotes to protect them from the shell.
Supported options: -I, -o, -D, -v, -W, -b.
.S - Erlang assembler source code. It generates a .beam file.
Supported options: same as for .erl.
.core - Erlang core source code. It generates a .beam file.
Supported options: same as for .erl.
.yrl - Yecc source code. It generates an .erl file.
Use option -I with the name of a file to use that file as a customized prologue file (option includefile).
Supported options: -o, -v, -I, -W.
.mib - MIB for SNMP. It generates a .bin file.
Supported options: -I, -o, -W.
.bin - A compiled MIB for SNMP. It generates a .hrl file.
Supported options: -o, -v.
.rel - Script file. It generates a boot file.
Use option -I to name directories to be searched for application files (equivalent to the path in the option list for systools:make_script/2).
Supported option: -o.
.asn1 - ASN1 file. It creates an .erl, .hrl, and .asn1db file from an .asn1 file. Also compiles the .erl using the Erlang compiler unless option +noobj is specified.
Supported options: -I, -o, -b, -W.
.idl - IC file. It runs the IDL compiler.
Supported options: -I, -o.

The compile server can be used to potentially speed up the build of multi-file projects by avoiding to start an Erlang system for each file to compile. Whether it will speed up the build depends on the nature of the project and the build machine.

By default, the compile server is not used. It can be enabled by giving erlc the option -server or by setting the environment variable ERLC_USE_SERVER to yes or true.

When the compile server is enabled, erlc will automatically use the server if it is started and start the server if has not already started. The server will terminate itself when it has been idle for some number of seconds.

erlc and the compile server communicate using the Erlang distribution. The compile server is started as a hidden node, with a name that includes the current user. Thus, each user on a computer has their own compile server.

Using the compile server does not always speed up the build, as the compile server sometimes must be restarted to ensure correctness. Here are some examples of situations that force a restart:

erl(1), m:compile, m:yecc, m:snmp

January 2025