This chapter describes the Objective Caml batch compiler ocamlc,
which compiles Caml source files to bytecode object files and link
these object files to produce standalone bytecode executable files.
These executable files are then run by the bytecode interpreter
ocamlrun.
The ocamlc command has a command-line interface similar to the one of
most C compilers. It accepts several types of arguments:
Arguments ending in .mli are taken to be source files for
compilation unit interfaces. Interfaces specify the names exported by
compilation units: they declare value names with their types, define
public data types, declare abstract data types, and so on. From the
file x.mli, the ocamlc compiler produces a compiled interface
in the file x.cmi.
Arguments ending in .ml are taken to be source files for compilation
unit implementations. Implementations provide definitions for the
names exported by the unit, and also contain expressions to be
evaluated for their side-effects. From the file x.ml, the ocamlc
compiler produces compiled object bytecode in the file x.cmo.
If the interface file x.mli exists, the implementation
x.ml is checked against the corresponding compiled interface
x.cmi, which is assumed to exist. If no interface
x.mli is provided, the compilation of x.ml produces a
compiled interface file x.cmi in addition to the compiled
object code file x.cmo. The file x.cmi produced
corresponds to an interface that exports everything that is defined in
the implementation x.ml.
Arguments ending in .cmo are taken to be compiled object bytecode. These
files are linked together, along with the object files obtained
by compiling .ml arguments (if any), and the Objective Caml standard
library, to produce a standalone executable program. The order in
which .cmo and .ml arguments are presented on the command line is
relevant: compilation units are initialized in that order at
run-time, and it is a link-time error to use a component of a unit
before having initialized it. Hence, a given x.cmo file must come
before all .cmo files that refer to the unit x.
Arguments ending in .cma are taken to be libraries of object bytecode.
A library of object bytecode packs in a single file a set of object
bytecode files (.cmo files). Libraries are built with ocamlc -a
(see the description of the -a option below). The object files
contained in the library are linked as regular .cmo files (see
above), in the order specified when the