erlc(1)
π NAME π
erlc β the Compiler β¨ (yes bestie, it compiles everything)
π DESCRIPTION π
okay so listen. erlc is the Erlang Module Definition era program that gives you one single, iconic way to run all the compilers in the Erlang system. it looks at the extension of each input file and is like "mmhm, i know which compiler this is" and invokes the right one. and here's the slay: no matter which compiler gets used, the same flags work for parameters like include paths and output directory. consistency? we love to see it. π
one thing though, and this is important: the current working directory, ".", is not included in the code path when the compiler runs. why? 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. no π« sketchy local Beam files hijacking your build. periodt.
π¦ erlc flags file1.ext file2.ext... π¦
compiles one or more files. and bestie, the files must include the extension β like .erl for Erlang source code, or .yrl for Yecc source code. erlc uses that extension to invoke the correct compiler. that's the whole trick. π₯
β¨ Generally Useful Flags β¨
the following flags are supported, and they're giving main character energy:
-I<Directory>β tells the compiler to go search for include files in Directory. when it bumps into an-includeor-include_libdirective, it searches for header files in this order:".", 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. yes, all of them. quote it. π-Werrorβ makes all warnings into errors. no more "it's just a warning" cope. π-W<Number>β sets warning level to Number. defaults to1. to turn off warnings, use-W0.-Wβ same as-W1. default. π-vβ enables verbose output. spill the tea, compiler. π«-b<Output_type>β specifies the type of output file. Output_type is 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. (they're monogamous like that. π)-no-serverβ do not use the compile server.-serverβ use the compile server.-enable-feature<Feature>β enables the feature feature during compilation. the special featureallcan be used to enable all features.-disable-feature<feature>β disables the feature feature during compilation. the special featureallcan be used to disable all non permanent features.-list-featuresβ list short descriptions of the current configurable features. non-configurable features (those with statusrejectedorpermanent) will not be shown. sorry to them. π-describe-feature<feature>β show long description and history of feature feature. lore dump unlocked. π-Mβ produces a Makefile rule to track header dependencies. the rule is sent tostdout. 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 to Makefile. 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 to Target.-MQ<Target>β as option-MT, except that characters special tomakeare 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. manifesting them into existence fr fr. π§--β signals that no more options will follow. the rest of the arguments is treated as filenames, even if they start with hyphens. fake-out defended. π‘οΈ+<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. (same rules as -D bestie, it's a whole thing.)
π Special Flags π
the following flags are useful in special situations, such as rebuilding the OTP system. lowkey niche, highkey powerful:
-pa<Directory>β appends Directory to 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 Directory to the code path in the invoked Erlang emulator.
π Supported Compilers π
the following compilers are supported, one per vibe:
.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.
- options
.Sβ Erlang assembler source code. it generates a.beamfile.- supported options: same as for
.erl.
- supported options: same as for
.coreβ Core Erlang source code. it generates a.beamfile.- supported options: same as for
.erl.
- supported options: same as for
.abstrβ Erlang abstract format as produced byto_abstr. it generates a.beamfile.- supported options: same as for
.erl.
- supported options: same as for
.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.
- use option
.mibβ MIB for SNMP. it generates a.binfile.- supported options:
-I,-o,-W.
- supported options:
.binβ a compiled MIB for SNMP. it generates a.hrlfile.- supported options:
-o,-v.
- supported options:
.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.
- use option
.asn1β ASN1 file. it creates an.erl,.hrl, and.asn1dbfile from an.asn1file. also compiles the.erlusing the Erlang compiler unless option+noobjis specified. multitasking queen. π- supported options:
-I,-o,-b,-W.
- supported options:
.idlβ IC file. it runs the IDL compiler.- supported options:
-I,-o.
- supported options:
π 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 actually speed up the build depends on the nature of the project and the build machine. no promises, bestie, it's giving "it depends." π
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. self-care. π€
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. yours is yours. π«Ά
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:
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, which must be just the path for the emulator without any parameters. defaults toerlin 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 areyesortrueto use the compile server, andnoorfalseto not use the compile server. if other values are given,erlcwill print a warning message and continue.ERLC_SERVER_IDβ tellserlcto identify the compile server by 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. parallel builds, no crossover, obsessed. π§ββοΈ
β See Also β
erl(1), compile, yecc, snmp β go read those too, iykyk π
and that's the whole page bestie!! this iconic piece of documentation was brought to you by Ericsson AB, running the erts 17.0.6 era, and it's erlc(1) β go compile something slay β¨π¦π
π¦ where this page comes from
- ubuntu stonking: erlang-base 1:29.0.6+dfsg-1 Β· Apache-2.0
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms