Command
erlc
Command Summary
Compiler
Description
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.
Exports
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.
Generally Useful Flags
The following flags are supported:
- -I <Directory>
-  Instructs the compiler to search for include files in the Directory. When encountering an-includeor-include_libdirective, the compiler searches for header files in the following directories:-  ".", the current working directory of the file server
-  The base name of the compiled file 
-  The directories specified using option -I; the directory specified last is searched first
 
-  
- -o <Directory>
-  The directory where the compiler is to place the output files. Defaults to the current working directory. 
- -D<Name>
-  Defines a macro. 
- -D<Name>=<Value>
-  Defines a macro with the specified value. The value can be any Erlang term. 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. 
- -WError
-  Makes all warnings into errors. 
- -W<Number>
-  Sets warning level to Number. Defaults to1. To turn off warnings, use-W0.
- -W
-  Same as -W1. Default.
- -v
-  Enables verbose output. 
- -b <Output_type>
-  Specifies the type of output file. Output_typeis the same as the file extension of the output file, but without the period. This option is ignored by compilers that have a single output format.
- -smp
-  Compiles using the SMP emulator. This is mainly useful for compiling native code, which must be compiled with the same runtime system that it is to be run on. 
- -no-server
-  Do not use the compile server.
- -server
-  Use the compile server.
- -M
-  Produces a Makefile rule to track header dependencies. The rule is sent to stdout. No object file is produced.
- -MMD
-  Generate dependencies as a side-effect. The object file will be produced as normal. This option overrides the option -M.
- -MF <Makefile>
-  As option -M, except that the Makefile is written toMakefile. No object file is produced.
- -MD
-  Same as -M -MF <File>.Pbeam.
- -MT <Target>
-  In conjunction with option -Mor-MF, changes the name of the rule emitted toTarget.
- -MQ <Target>
-  As option -MT, except that characters special tomake/1are quoted.
- -MP
-  In conjunction with option -Mor-MF, adds a phony target for each dependency.
- -MG
-  In conjunction with option -Mor-MF, considers missing headers as generated files and adds them to the dependencies.
- --
-  Signals that no more options will follow. The rest of the arguments is treated as filenames, even if they start with hyphens. 
- +<Term>
-  A flag starting with a plus ( +) rather than a hyphen is converted to an Erlang term and passed unchanged to the compiler. For example, optionexport_allfor the Erlang compiler can be specified as follows: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. 
Special Flags
The following flags are useful in special situations, such as rebuilding the OTP system:
- -pa <Directory>
-  Appends Directoryto the front of the code path in the invoked Erlang emulator. This can be used to invoke another compiler than the default one.
- -pz <Directory>
-  Appends Directoryto the code path in the invoked Erlang emulator.
Supported Compilers
The following compilers are supported:
- .erl
-  Erlang source code. It generates a .beamfile.Options -P,-E, and-Sare 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 .beamfile.Supported options: same as for .erl.
- .core
-  Erlang core source code. It generates a .beamfile.Supported options: same as for .erl.
- .yrl
-  Yecc source code. It generates an .erlfile.Use option -Iwith the name of a file to use that file as a customized prologue file (optionincludefile).Supported options: -o,-v,-I,-W.
- .mib
-  MIB for SNMP. It generates a .binfile.Supported options: -I,-o,-W.
- .bin
-  A compiled MIB for SNMP. It generates a .hrlfile.Supported options: -o,-v.
- .rel
-  Script file. It generates a boot file. Use option -Ito name directories to be searched for application files (equivalent to thepathin the option list forsystools:make_script/2).Supported option: -o.
- .asn1
-  ASN1 file. It creates an .erl,.hrl, and.asn1dbfile from an.asn1file. Also compiles the.erlusing the Erlang compiler unless option+noobjis specified.Supported options: -I,-o,-b,-W.
- .idl
-  IC file. It runs the IDL compiler. Supported options: -I,-o.
Compile Server
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 situtations that force a restart:
-  erlcwants to use a different version of Erlang than the compile server is using.
-  erlcwants to use different options forerlthan the compile server was started with. (A change to code path using the option-pacould cause different parse transforms to be loaded. To be safe, the compile server will be restarted when anyerloption is changed.)
- If the current working directory for erlcis different from the working directory active when the compile server was started, and if the compile server has active jobs, it will be restarted as soon as those jobs have finished. (Build systems that build files randomly across multiple directories in parallel will probably not benefit from the compile server.)
Environment Variables
- ERLC_EMULATOR
- The command for starting the emulator. Defaults to erlin the same directory as theerlcprogram itself, or, if it does not exist,erlin any of the directories specified in environment variablePATH.
- ERLC_USE_SERVER
- Allowed values are yesortrueto use thecompile server, andnoorfalseto not use the compile server. If other values are given,erlcwill print a warning message and continue.
- ERLC_SERVER_ID
- Tells erlcto identify thecompile serverby the given name, allowing a single user to run multiple unrelated builds in parallel without them affecting each other, which can be useful for shared build machines and the like. The name must be alphanumeric, and it defaults to being empty.
See Also
erl(1), compile(3), yecc(3), snmp(3)
    © 2010–2020 Ericsson AB
Licensed under the Apache License, Version 2.0.