1erlc(1)                          User Commands                         erlc(1)
2
3
4

NAME

6       erlc - Compiler
7

DESCRIPTION

9       The  erlc  program  provides  a  common way to run all compilers in the
10       Erlang system. Depending on the extension  of  each  input  file,  erlc
11       invokes the appropriate compiler. Regardless of which compiler is used,
12       the same flags are used to provide parameters, such  as  include  paths
13       and output directory.
14
15       The  current  working  directory, ".", is not included in the code path
16       when running the compiler. This is to avoid loading Beam files from the
17       current  working  directory  that could potentially be in conflict with
18       the compiler or the Erlang/OTP system used by the compiler.
19

EXPORTS

21       erlc flags file1.ext file2.ext...
22
23              Compiles one or more files. The files must  include  the  exten‐
24              sion, for example, .erl for Erlang source code, or .yrl for Yecc
25              source code. Erlc uses the extension to invoke the correct  com‐
26              piler.
27

GENERALLY USEFUL FLAGS

29       The following flags are supported:
30
31         -I <Directory>:
32           Instructs  the  compiler  to search for include files in the Direc‐
33           tory. When encountering an -include or -include_lib directive,  the
34           compiler searches for header files in the following directories:
35
36           * ".", the current working directory of the file server
37
38           * The base name of the compiled file
39
40           * The  directories  specified using option -I; the directory speci‐
41             fied last is searched first
42
43         -o <Directory>:
44           The directory where the compiler is  to  place  the  output  files.
45           Defaults to the current working directory.
46
47         -D<Name>:
48           Defines a macro.
49
50         -D<Name>=<Value>:
51           Defines  a  macro  with  the  specified value. The value can be any
52           Erlang term. Depending on the platform, the value may  need  to  be
53           quoted  if the shell itself interprets certain characters. On Unix,
54           terms containing tuples and lists must be quoted. Terms  containing
55           spaces must be quoted on all platforms.
56
57         -W<Error>:
58           Makes all warnings into errors.
59
60         -W<Number>:
61           Sets  warning level to Number. Defaults to 1. To turn off warnings,
62           use -W0.
63
64         -W:
65           Same as -W1. Default.
66
67         -v:
68           Enables verbose output.
69
70         -b <Output_type>:
71           Specifies the type of output file. Output_type is the same  as  the
72           file  extension  of  the  output file, but without the period. This
73           option is ignored by compilers that have a single output format.
74
75         -smp:
76           Compiles using the SMP emulator. This is mainly useful for  compil‐
77           ing  native code, which must be compiled with the same runtime sys‐
78           tem that it is to be run on.
79
80         -no-server:
81           Do not use the compile server.
82
83         -server:
84           Use the compile server.
85
86         -M:
87           Produces a Makefile rule to track header dependencies. The rule  is
88           sent to stdout. No object file is produced.
89
90         -MMD:
91           Generate  dependencies  as  a  side-effect. The object file will be
92           produced as normal. This option overrides the option -M.
93
94         -MF <Makefile>:
95           As option -M, except that the Makefile is written to  Makefile.  No
96           object file is produced.
97
98         -MD:
99           Same as -M -MF <File>.Pbeam.
100
101         -MT <Target>:
102           In  conjunction with option -M or -MF, changes the name of the rule
103           emitted to Target.
104
105         -MQ <Target>:
106           As option -MT, except that characters special to make/1 are quoted.
107
108         -MP:
109           In conjunction with option -M or -MF, adds a phony target for  each
110           dependency.
111
112         -MG:
113           In  conjunction with option -M or -MF, considers missing headers as
114           generated files and adds them to the dependencies.
115
116         --:
117           Signals that no more options will follow. The rest of the arguments
118           is treated as filenames, even if they start with hyphens.
119
120         +<Term>:
121           A  flag  starting with a plus (+) rather than a hyphen is converted
122           to an Erlang term and passed unchanged to the compiler.  For  exam‐
123           ple,  option export_all for the Erlang compiler can be specified as
124           follows:
125
126         erlc +export_all file.erl
127
128           Depending on the platform, the value may need to be quoted  if  the
129           shell itself interprets certain characters. On Unix, terms contain‐
130           ing tuples and lists must be quoted. Terms containing  spaces  must
131           be quoted on all platforms.
132

SPECIAL FLAGS

134       The  following flags are useful in special situations, such as rebuild‐
135       ing the OTP system:
136
137         -pa <Directory>:
138           Appends Directory to the front of the  code  path  in  the  invoked
139           Erlang  emulator.  This can be used to invoke another compiler than
140           the default one.
141
142         -pz <Directory>:
143           Appends Directory to the code path in the invoked Erlang emulator.
144

SUPPORTED COMPILERS

146       The following compilers are supported:
147
148         .erl:
149           Erlang source code. It generates a .beam file.
150
151           Options -P, -E, and -S are equivalent  to  +'P',  +'E',  and  +'S',
152           except  that  it  is  not necessary to include the single quotes to
153           protect them from the shell.
154
155           Supported options: -I, -o, -D, -v, -W, -b.
156
157         .S:
158           Erlang assembler source code. It generates a .beam file.
159
160           Supported options: same as for .erl.
161
162         .core:
163           Erlang core source code. It generates a .beam file.
164
165           Supported options: same as for .erl.
166
167         .yrl:
168           Yecc source code. It generates an .erl file.
169
170           Use option -I with the name of a file to use that file as a custom‐
171           ized prologue file (option includefile).
172
173           Supported options: -o, -v, -I, -W.
174
175         .mib:
176           MIB for SNMP. It generates a .bin file.
177
178           Supported options: -I, -o, -W.
179
180         .bin:
181           A compiled MIB for SNMP. It generates a .hrl file.
182
183           Supported options: -o, -v.
184
185         .rel:
186           Script file. It generates a boot file.
187
188           Use  option  -I  to name directories to be searched for application
189           files  (equivalent  to  the  path  in  the  option  list  for  sys‐
190           tools:make_script/2).
191
192           Supported option: -o.
193
194         .asn1:
195           ASN1 file. It creates an .erl, .hrl, and .asn1db file from an .asn1
196           file. Also compiles the  .erl  using  the  Erlang  compiler  unless
197           option +noobj is specified.
198
199           Supported options: -I, -o, -b, -W.
200
201         .idl:
202           IC file. It runs the IDL compiler.
203
204           Supported options: -I, -o.
205

COMPILE SERVER

207       The  compile  server  can  be used to potentially speed up the build of
208       multi-file projects by avoiding to start an Erlang system for each file
209       to compile. Whether it will speed up the build depends on the nature of
210       the project and the build machine.
211
212       By default, the compile server is not used. It can be enabled by giving
213       erlc  the  option  -server  or  by  setting  the  environment  variable
214       ERLC_USE_SERVER to yes or true.
215
216       When the compile server is enabled, erlc  will  automatically  use  the
217       server  if  it  is  started  and  start  the  server if has not already
218       started. The server will terminate itself when it  has  been  idle  for
219       some number of seconds.
220
221       erlc  and the compile server communicate using the Erlang distribution.
222       The compile server is started as  a  hidden  node,  with  a  name  that
223       includes  the current user. Thus, each user on a computer has their own
224       compile server.
225
226       Using the compile server does not always speed up  the  build,  as  the
227       compile  server sometimes must be restarted to ensure correctness. Here
228       are some examples of situtations that force a restart:
229
230         * erlc wants to use a different version of Erlang  than  the  compile
231           server is using.
232
233         * erlc wants to use different options for erl than the compile server
234           was started with. (A change to code path using the option -pa could
235           cause different parse transforms to be loaded. To be safe, the com‐
236           pile server will be restarted when any erl option is changed.)
237
238         * If the current working directory for erlc  is  different  from  the
239           working  directory  active when the compile server was started, and
240           if the compile server has active jobs, it will be restarted as soon
241           as  those  jobs have finished. (Build systems that build files ran‐
242           domly across multiple directories in  parallel  will  probably  not
243           benefit from the compile server.)
244

ENVIRONMENT VARIABLES

246         ERLC_EMULATOR:
247           The  command for starting the emulator. Defaults to erl in the same
248           directory as the erlc program itself, or, if it does not exist, erl
249           in any of the directories specified in environment variable PATH.
250
251         ERLC_USE_SERVER:
252           Allowed values are yes or true to use the compile server, and no or
253           false to not use the compile server. If  other  values  are  given,
254           erlc will print a warning message and continue.
255
256         ERLC_SERVER_ID:
257           Tells erlc to identify the compile server by the given name, allow‐
258           ing a single user to run  multiple  unrelated  builds  in  parallel
259           without  them  affecting each other, which can be useful for shared
260           build machines and the like. The name must be alphanumeric, and  it
261           defaults to being empty.
262

SEE ALSO

264       erl(1), compile(3), yecc(3), snmp(3)
265
266
267
268Ericsson AB                       erts 10.7.1                          erlc(1)
Impressum