This chapter describes the Objective Caml high-performance
native-code compiler ocamlopt, which compiles Caml source files to
native code object files and link these object files to produce
standalone executables.
The native-code compiler is only available on certain platforms.
It produces code that runs faster than the bytecode produced by
ocamlc, at the cost of increased compilation time and executable code
size. Compatibility with the bytecode compiler is extremely high: the
same source code should run identically when compiled with ocamlc and
ocamlopt.
It is not possible to mix native-code object files produced by ocamlc
with bytecode object files produced by ocamlopt: a program must be
compiled entirely with ocamlopt or entirely with ocamlc. Native-code
object files produced by ocamlopt cannot be loaded in the toplevel
system ocaml.
The ocamlopt command has a command-line interface very close to that
of ocamlc. It accepts the same 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 ocamlopt compiler produces a compiled interface
in the file x.cmi. The interface produced is identical to that
produced by the bytecode compiler ocamlc.
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 ocamlopt
compiler produces two files: x.o, containing native object code,
and x.cmx, containing extra information for linking and
optimization of the clients of the unit. The compiled implementation
should always be referred to under the name x.cmx (when given
a .o file, ocamlopt assumes that it contains code compiled from C,
not from Caml).
The implementation is checked against the interface file x.mli
(if it exists) as described in the manual for ocamlc
(chapter 8).
Arguments ending in .cmx are taken to be compiled object code. These
files are linked together, along with the object files obtained
by compiling .ml arguments (if any), and the Caml standard
library, to produce a native-code executable program. The order in
which .cmx and .ml arguments are p