Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > 29d4b60c68c6b2dac6b16939691f8a13 > files > 255

ocaml-doc-4.01.0-3.mga4.noarch.rpm

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="generator" content="hevea 2.00">
<link rel="stylesheet" type="text/css" href="manual.css">
<title>Native-code compilation (ocamlopt)</title>
</head>
<body>
<a href="runtime.html"><img src="previous_motif.gif" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up"></a>
<a href="lexyacc.html"><img src="next_motif.gif" alt="Next"></a>
<hr>
<h1 class="chapter" id="sec258">Chapter&#XA0;11&#XA0;&#XA0;Native-code compilation (ocamlopt)</h1>
<ul>
<li><a href="native.html#sec259">Overview of the compiler</a>
</li><li><a href="native.html#sec260">Options</a>
</li><li><a href="native.html#sec264">Common errors</a>
</li><li><a href="native.html#sec265">Running executables produced by ocamlopt</a>
</li><li><a href="native.html#sec266">Compatibility with the bytecode compiler</a>
</li></ul>
<p> <a id="c:nativecomp"></a>

</p><p>This chapter describes the OCaml high-performance
native-code compiler <span class="c007">ocamlopt</span>, which compiles OCaml source files to
native code object files and link these object files to produce
standalone executables.</p><p>The native-code compiler is only available on certain platforms.
It produces code that runs faster than the bytecode produced by
<span class="c007">ocamlc</span>, 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 <span class="c007">ocamlc</span> and
<span class="c007">ocamlopt</span>.</p><p>It is not possible to mix native-code object files produced by <span class="c007">ocamlopt</span>
with bytecode object files produced by <span class="c007">ocamlc</span>: a program must be
compiled entirely with <span class="c007">ocamlopt</span> or entirely with <span class="c007">ocamlc</span>. Native-code
object files produced by <span class="c007">ocamlopt</span> cannot be loaded in the toplevel
system <span class="c007">ocaml</span>.</p>
<h2 class="section" id="sec259">11.1&#XA0;&#XA0;Overview of the compiler</h2>
<p>The <span class="c007">ocamlopt</span> command has a command-line interface very close to that
of <span class="c007">ocamlc</span>. It accepts the same types of arguments, and processes them
sequentially:</p><ul class="itemize"><li class="li-itemize">
Arguments ending in <span class="c007">.mli</span> 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 <span class="c013">x</span><span class="c007">.mli</span>, the <span class="c007">ocamlopt</span> compiler produces a compiled interface
in the file <span class="c013">x</span><span class="c007">.cmi</span>. The interface produced is identical to that
produced by the bytecode compiler <span class="c007">ocamlc</span>.</li><li class="li-itemize">Arguments ending in <span class="c007">.ml</span> 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 <span class="c013">x</span><span class="c007">.ml</span>, the <span class="c007">ocamlopt</span>
compiler produces two files: <span class="c013">x</span><span class="c007">.o</span>, containing native object code,
and <span class="c013">x</span><span class="c007">.cmx</span>, containing extra information for linking and
optimization of the clients of the unit. The compiled implementation
should always be referred to under the name <span class="c013">x</span><span class="c007">.cmx</span> (when given
a <span class="c007">.o</span> or <span class="c007">.obj</span> file, <span class="c007">ocamlopt</span> assumes that it contains code compiled from C,
not from OCaml).<p>The implementation is checked against the interface file <span class="c013">x</span><span class="c007">.mli</span>
(if it exists) as described in the manual for <span class="c007">ocamlc</span>
(chapter&#XA0;<a href="comp.html#c%3Acamlc">8</a>).</p></li><li class="li-itemize">Arguments ending in <span class="c007">.cmx</span> are taken to be compiled object code. These
files are linked together, along with the object files obtained
by compiling <span class="c007">.ml</span> arguments (if any), and the OCaml standard
library, to produce a native-code executable program. The order in
which <span class="c007">.cmx</span> and <span class="c007">.ml</span> 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 <span class="c013">x</span><span class="c007">.cmx</span> file must come
before all <span class="c007">.cmx</span> files that refer to the unit <span class="c013">x</span>.</li><li class="li-itemize">Arguments ending in <span class="c007">.cmxa</span> are taken to be libraries of object code.
Such a library packs in two files (<span class="c013">lib</span><span class="c007">.cmxa</span> and <span class="c013">lib</span><span class="c007">.a</span>/<span class="c007">.lib</span>)
a set of object files (<span class="c007">.cmx</span> and <span class="c007">.o</span>/<span class="c007">.obj</span> files). Libraries are build with
<span class="c007">ocamlopt -a</span> (see the description of the <span class="c007">-a</span> option below). The object
files contained in the library are linked as regular <span class="c007">.cmx</span> files (see
above), in the order specified when the library was built. The only
difference is that if an object file contained in a library is not
referenced anywhere in the program, then it is not linked in.</li><li class="li-itemize">Arguments ending in <span class="c007">.c</span> are passed to the C compiler, which generates
a <span class="c007">.o</span>/<span class="c007">.obj</span> object file. This object file is linked with the program.</li><li class="li-itemize">Arguments ending in <span class="c007">.o</span>, <span class="c007">.a</span> or <span class="c007">.so</span> (<span class="c007">.obj</span>, <span class="c007">.lib</span> and <span class="c007">.dll</span>
under Windows) are assumed to be C object files and
libraries. They are linked with the program.</li></ul><p>The output of the linking phase is a regular Unix or Windows
executable file. It does not need <span class="c007">ocamlrun</span> to run.</p>
<h2 class="section" id="sec260">11.2&#XA0;&#XA0;Options</h2>
<p>The following command-line options are recognized by <span class="c007">ocamlopt</span>.
The options <span class="c007">-pack</span>, <span class="c007">-a</span>, <span class="c007">-shared</span>, <span class="c007">-c</span> and <span class="c007">-output-obj</span> are mutually
exclusive.</p><dl class="description"><dt class="dt-description"><span class="c010">-a</span></dt><dd class="dd-description">
Build a library (<span class="c007">.cmxa</span> and <span class="c007">.a</span>/<span class="c007">.lib</span> files) with the object files
(<span class="c007">.cmx</span> and <span class="c007">.o</span>/<span class="c007">.obj</span> files) given on the command line, instead of
linking them into an executable file. The name of the library must be
set with the <span class="c007">-o</span> option.<p>If <span class="c007">-cclib</span> or <span class="c007">-ccopt</span> options are passed on the command
line, these options are stored in the resulting <span class="c007">.cmxa</span> library. Then,
linking with this library automatically adds back the
<span class="c007">-cclib</span> and <span class="c007">-ccopt</span> options as if they had been provided on the
command line, unless the <span class="c007">-noautolink</span> option is given.</p></dd><dt class="dt-description"><span class="c010">-absname</span></dt><dd class="dd-description">
Force error messages to show absolute paths for file names.</dd><dt class="dt-description"><span class="c010">-annot</span></dt><dd class="dd-description">
Dump detailed information about the compilation (types, bindings,
tail-calls, etc). The information for file <span class="c013">src</span><span class="c007">.ml</span>
is put into file <span class="c013">src</span><span class="c007">.annot</span>. In case of a type error, dump
all the information inferred by the type-checker before the error.
The <span class="c013">src</span><span class="c007">.annot</span> file can be used with the emacs commands given in
<span class="c007">emacs/caml-types.el</span> to display types and other annotations
interactively.</dd><dt class="dt-description"><span class="c010">-c</span></dt><dd class="dd-description">
Compile only. Suppress the linking phase of the
compilation. Source code files are turned into compiled files, but no
executable file is produced. This option is useful to
compile modules separately.</dd><dt class="dt-description"><span class="c019"><span class="c007">-cc</span> <span class="c013">ccomp</span></span></dt><dd class="dd-description">
Use <span class="c013">ccomp</span> as the C linker called to build the final executable
and as the C compiler for compiling <span class="c007">.c</span> source files.</dd><dt class="dt-description"><span class="c019"><span class="c007">-cclib</span> <span class="c007">-l</span><span class="c013">libname</span></span></dt><dd class="dd-description">
Pass the <span class="c007">-l</span><span class="c013">libname</span> option to the linker. This causes the given
C library to be linked with the program.</dd><dt class="dt-description"><span class="c019"><span class="c007">-ccopt</span> <span class="c013">option</span></span></dt><dd class="dd-description">
Pass the given option to the C compiler and linker. For instance,
<span class="c007">-ccopt -L</span><span class="c013">dir</span> causes the C linker to search for C libraries in
directory <span class="c013">dir</span>.</dd><dt class="dt-description"><span class="c010">-compact</span></dt><dd class="dd-description">
Optimize the produced code for space rather than for time. This
results in slightly smaller but slightly slower programs. The default is to
optimize for speed.</dd><dt class="dt-description"><span class="c010">-config</span></dt><dd class="dd-description">
Print the version number of <span class="c007">ocamlopt</span> and a detailed summary of its
configuration, then exit.</dd><dt class="dt-description"><span class="c019"><span class="c007">-for-pack</span> <span class="c013">module-path</span></span></dt><dd class="dd-description">
Generate an object file (<span class="c007">.cmx</span> and <span class="c007">.o</span>/<span class="c007">.obj</span> files) that can later be included
as a sub-module (with the given access path) of a compilation unit
constructed with <span class="c007">-pack</span>. For instance, <span class="c007">ocamlopt -for-pack P -c A.ml</span>
will generate <span class="c007">a.cmx</span> and <span class="c007">a.o</span> files that can later be used with
<span class="c007">ocamlopt -pack -o P.cmx a.cmx</span>.</dd><dt class="dt-description"><span class="c010">-g</span></dt><dd class="dd-description">
Add debugging information while compiling and linking. This option is
required in order to produce stack backtraces when
the program terminates on an uncaught exception (see
section&#XA0;<a href="runtime.html#ocamlrun-options">10.2</a>).</dd><dt class="dt-description"><span class="c010">-i</span></dt><dd class="dd-description">
Cause the compiler to print all defined names (with their inferred
types or their definitions) when compiling an implementation (<span class="c007">.ml</span>
file). No compiled files (<span class="c007">.cmo</span> and <span class="c007">.cmi</span> files) are produced.
This can be useful to check the types inferred by the
compiler. Also, since the output follows the syntax of interfaces, it
can help in writing an explicit interface (<span class="c007">.mli</span> file) for a file:
just redirect the standard output of the compiler to a <span class="c007">.mli</span> file,
and edit that file to remove all declarations of unexported names.</dd><dt class="dt-description"><span class="c019"><span class="c007">-I</span> <span class="c013">directory</span></span></dt><dd class="dd-description">
Add the given directory to the list of directories searched for
compiled interface files (<span class="c007">.cmi</span>), compiled object code files
(<span class="c007">.cmx</span>), and libraries (<span class="c007">.cmxa</span>). By default, the current directory
is searched first, then the standard library directory. Directories
added with <span class="c007">-I</span> are searched after the current directory, in the order
in which they were given on the command line, but before the standard
library directory.<p>If the given directory starts with <span class="c007">+</span>, it is taken relative to the
standard library directory. For instance, <span class="c007">-I +labltk</span> adds the
subdirectory <span class="c007">labltk</span> of the standard library to the search path.</p></dd><dt class="dt-description"><span class="c019"><span class="c007">-impl</span> <span class="c013">filename</span></span></dt><dd class="dd-description">
Compile the file <span class="c013">filename</span> as an implementation file, even if its
extension is not <span class="c007">.ml</span>.</dd><dt class="dt-description"><span class="c019"><span class="c007">-inline</span> <span class="c013">n</span></span></dt><dd class="dd-description">
Set aggressiveness of inlining to <span class="c013">n</span>, where <span class="c013">n</span> is a positive
integer. Specifying <span class="c007">-inline 0</span> prevents all functions from being
inlined, except those whose body is smaller than the call site. Thus,
inlining causes no expansion in code size. The default aggressiveness,
<span class="c007">-inline 1</span>, allows slightly larger functions to be inlined, resulting
in a slight expansion in code size. Higher values for the <span class="c007">-inline</span>
option cause larger and larger functions to become candidate for
inlining, but can result in a serious increase in code size.</dd><dt class="dt-description"><span class="c019"><span class="c007">-intf</span> <span class="c013">filename</span></span></dt><dd class="dd-description">
Compile the file <span class="c013">filename</span> as an interface file, even if its
extension is not <span class="c007">.mli</span>.</dd><dt class="dt-description"><span class="c019"><span class="c007">-intf-suffix</span> <span class="c013">string</span></span></dt><dd class="dd-description">
Recognize file names ending with <span class="c013">string</span> as interface files
(instead of the default <span class="c007">.mli</span>).</dd><dt class="dt-description"><span class="c010">-labels</span></dt><dd class="dd-description">
Labels are not ignored in types, labels may be used in applications,
and labelled parameters can be given in any order. This is the default.</dd><dt class="dt-description"><span class="c010">-linkall</span></dt><dd class="dd-description">
Force all modules contained in libraries to be linked in. If this
flag is not given, unreferenced modules are not linked in. When
building a library (<span class="c007">-a</span> flag), setting the <span class="c007">-linkall</span> flag forces all
subsequent links of programs involving that library to link all the
modules contained in the library.</dd><dt class="dt-description"><span class="c010">-noassert</span></dt><dd class="dd-description">
Do not compile assertion checks. Note that the special form
<span class="c007">assert false</span> is always compiled because it is typed specially.
This flag has no effect when linking already-compiled files.</dd><dt class="dt-description"><span class="c010">-noautolink</span></dt><dd class="dd-description">
When linking <span class="c007">.cmxa</span> libraries, ignore <span class="c007">-cclib</span> and <span class="c007">-ccopt</span>
options potentially contained in the libraries (if these options were
given when building the libraries). This can be useful if a library
contains incorrect specifications of C libraries or C options; in this
case, during linking, set <span class="c007">-noautolink</span> and pass the correct C
libraries and options on the command line.</dd><dt class="dt-description"><span class="c010">-nodynlink</span></dt><dd class="dd-description">
Allow the compiler to use some optimizations that are valid only for code
that is never dynlinked.</dd><dt class="dt-description"><span class="c010">-nolabels</span></dt><dd class="dd-description">
Ignore non-optional labels in types. Labels cannot be used in
applications, and parameter order becomes strict.</dd><dt class="dt-description"><span class="c019"><span class="c007">-o</span> <span class="c013">exec-file</span></span></dt><dd class="dd-description">
Specify the name of the output file produced by the linker. The
default output name is <span class="c007">a.out</span> under Unix and <span class="c007">camlprog.exe</span> under
Windows. If the <span class="c007">-a</span> option is given, specify the name of the library
produced. If the <span class="c007">-pack</span> option is given, specify the name of the
packed object file produced. If the <span class="c007">-output-obj</span> option is given,
specify the name of the output file produced. If the <span class="c007">-shared</span> option
is given, specify the name of plugin file produced.</dd><dt class="dt-description"><span class="c010">-output-obj</span></dt><dd class="dd-description">
Cause the linker to produce a C object file instead of an executable
file. This is useful to wrap OCaml code as a C library,
callable from any C program. See chapter&#XA0;<a href="intfc.html#sec404">19</a>,
section&#XA0;<a href="intfc.html#s%3Aembedded-code">19.7.5</a>. The name of the output object file
must be set with the <span class="c007">-o</span> option.
This option can also be used to produce a compiled shared/dynamic
library (<span class="c007">.so</span> extension, <span class="c007">.dll</span> under Windows).</dd><dt class="dt-description"><span class="c010">-p</span></dt><dd class="dd-description">
Generate extra code to write profile information when the program is
executed. The profile information can then be examined with the
analysis program <span class="c007">gprof</span>. (See chapter&#XA0;<a href="profil.html#c%3Aprofiler">17</a> for more
information on profiling.) The <span class="c007">-p</span> option must be given both at
compile-time and at link-time. Linking object files not compiled with
<span class="c007">-p</span> is possible, but results in less precise profiling.<blockquote class="quote"><span class="c011">Unix:</span>&#XA0;&#XA0; See the Unix manual page for <span class="c007">gprof(1)</span> for more
information about the profiles.<p>Full support for <span class="c007">gprof</span> is only available for certain platforms
(currently: Intel x86 32 and 64 bits under Linux, BSD and MacOS X).
On other platforms, the <span class="c007">-p</span> option will result in a less precise
profile (no call graph information, only a time profile).
</p></blockquote><blockquote class="quote"><span class="c011">Windows:</span>&#XA0;&#XA0;
The <span class="c007">-p</span> option does not work under Windows.
</blockquote></dd><dt class="dt-description"><span class="c010">-pack</span></dt><dd class="dd-description">
Build an object file (<span class="c007">.cmx</span> and <span class="c007">.o</span>/<span class="c007">.obj</span> files) and its associated compiled
interface (<span class="c007">.cmi</span>) that combines the <span class="c007">.cmx</span> object
files given on the command line, making them appear as sub-modules of
the output <span class="c007">.cmx</span> file. The name of the output <span class="c007">.cmx</span> file must be
given with the <span class="c007">-o</span> option. For instance,
<pre>        ocamlopt -pack -o P.cmx A.cmx B.cmx C.cmx
</pre>generates compiled files <span class="c007">P.cmx</span>, <span class="c007">P.o</span> and <span class="c007">P.cmi</span> describing a
compilation unit having three sub-modules <span class="c007">A</span>, <span class="c007">B</span> and <span class="c007">C</span>,
corresponding to the contents of the object files <span class="c007">A.cmx</span>, <span class="c007">B.cmx</span> and
<span class="c007">C.cmx</span>. These contents can be referenced as <span class="c007">P.A</span>, <span class="c007">P.B</span> and <span class="c007">P.C</span>
in the remainder of the program.<p>The <span class="c007">.cmx</span> object files being combined must have been compiled with
the appropriate <span class="c007">-for-pack</span> option. In the example above,
<span class="c007">A.cmx</span>, <span class="c007">B.cmx</span> and <span class="c007">C.cmx</span> must have been compiled with
<span class="c007">ocamlopt -for-pack P</span>.</p><p>Multiple levels of packing can be achieved by combining <span class="c007">-pack</span> with
<span class="c007">-for-pack</span>. Consider the following example:
</p><pre>        ocamlopt -for-pack P.Q -c A.ml
        ocamlopt -pack -o Q.cmx -for-pack P A.cmx
        ocamlopt -for-pack P -c B.ml
        ocamlopt -pack -o P.cmx Q.cmx B.cmx
</pre><p>The resulting <span class="c007">P.cmx</span> object file has sub-modules <span class="c007">P.Q</span>, <span class="c007">P.Q.A</span>
and <span class="c007">P.B</span>.</p></dd><dt class="dt-description"><span class="c019"><span class="c007">-pp</span> <span class="c013">command</span></span></dt><dd class="dd-description">
Cause the compiler to call the given <span class="c013">command</span> as a preprocessor
for each source file. The output of <span class="c013">command</span> is redirected to
an intermediate file, which is compiled. If there are no compilation
errors, the intermediate file is deleted afterwards.</dd><dt class="dt-description"><span class="c010">-principal</span></dt><dd class="dd-description">
Check information path during type-checking, to make sure that all
types are derived in a principal way. All programs accepted in
<span class="c007">-principal</span> mode are also accepted in default mode with equivalent
types, but different binary signatures.</dd><dt class="dt-description"><span class="c010">-rectypes</span></dt><dd class="dd-description">
Allow arbitrary recursive types during type-checking. By default,
only recursive types where the recursion goes through an object type
are supported. Note that once you have created an interface using this
flag, you must use it again for all dependencies.</dd><dt class="dt-description"><span class="c010">-S</span></dt><dd class="dd-description">
Keep the assembly code produced during the compilation. The assembly
code for the source file <span class="c013">x</span><span class="c007">.ml</span> is saved in the file <span class="c013">x</span><span class="c007">.s</span>.</dd><dt class="dt-description"><span class="c010">-shared</span></dt><dd class="dd-description">
Build a plugin (usually <span class="c007">.cmxs</span>) that can be dynamically loaded with
the <span class="c007">Dynlink</span> module. The name of the plugin must be
set with the <span class="c007">-o</span> option. A plugin can include a number of OCaml
modules and libraries, and extra native objects (<span class="c007">.o</span>, <span class="c007">.obj</span>, <span class="c007">.a</span>,
<span class="c007">.lib</span> files). Building native plugins is only supported for some
operating system. Under some systems (currently,
only Linux AMD 64), all the OCaml code linked in a plugin must have
been compiled without the <span class="c007">-nodynlink</span> flag. Some constraints might also
apply to the way the extra native objects have been compiled (under
Linux AMD 64, they must contain only position-independent code).</dd><dt class="dt-description"><span class="c010">-thread</span></dt><dd class="dd-description">
Compile or link multithreaded programs, in combination with the
system <span class="c007">threads</span> library described in chapter&#XA0;<a href="libthreads.html#c%3Athreads">25</a>.</dd><dt class="dt-description"><span class="c010">-unsafe</span></dt><dd class="dd-description">
Turn bound checking off for array and string accesses (the <span class="c007">v.(i)</span> and
<span class="c007">s.[i]</span> constructs). Programs compiled with <span class="c007">-unsafe</span> are therefore
faster, but unsafe: anything can happen if the program accesses an
array or string outside of its bounds. Additionally, turn off the
check for zero divisor in integer division and modulus operations.
With <span class="c007">-unsafe</span>, an integer division (or modulus) by zero can halt the
program or continue with an unspecified result instead of raising a
<span class="c007">Division_by_zero</span> exception.</dd><dt class="dt-description"><span class="c010">-v</span></dt><dd class="dd-description">
Print the version number of the compiler and the location of the
standard library directory, then exit.</dd><dt class="dt-description"><span class="c010">-verbose</span></dt><dd class="dd-description">
Print all external commands before they are executed, in particular
invocations of the assembler, C compiler, and linker.</dd><dt class="dt-description"><span class="c019"><span class="c007">-vnum</span> or <span class="c007">-version</span></span></dt><dd class="dd-description">
Print the version number of the compiler in short form (e.g. <span class="c007">3.11.0</span>),
then exit.</dd><dt class="dt-description"><span class="c019"><span class="c007">-w</span> <span class="c013">warning-list</span></span></dt><dd class="dd-description">
Enable, disable, or mark as errors the warnings specified by the argument
<span class="c013">warning-list</span>.
Each warning can be <em>enabled</em> or <em>disabled</em>, and each warning
can be <em>marked</em> or <em>unmarked</em>.
If a warning is disabled, it isn&#X2019;t displayed and doesn&#X2019;t affect
compilation in any way (even if it is marked). If a warning is
enabled, it is displayed normally by the compiler whenever the source
code triggers it. If it is enabled and marked, the compiler will stop
with an error after displaying that warning if the source code
triggers it.<p>The <span class="c013">warning-list</span> argument is a sequence of warning specifiers,
with no separators between them. A warning specifier is one of the
following:</p><dl class="description"><dt class="dt-description">
<span class="c019"><span class="c007">+</span><span class="c013">num</span></span></dt><dd class="dd-description"> Enable warning number <span class="c013">num</span>.
</dd><dt class="dt-description"><span class="c019"><span class="c007">-</span><span class="c013">num</span></span></dt><dd class="dd-description"> Disable warning number <span class="c013">num</span>.
</dd><dt class="dt-description"><span class="c019"><span class="c007">@</span><span class="c013">num</span></span></dt><dd class="dd-description"> Enable and mark warning number <span class="c013">num</span>.
</dd><dt class="dt-description"><span class="c019"><span class="c007">+</span><span class="c013">num1</span>..<span class="c013">num2</span></span></dt><dd class="dd-description"> Enable warnings in the given range.
</dd><dt class="dt-description"><span class="c019"><span class="c007">-</span><span class="c013">num1</span>..<span class="c013">num2</span></span></dt><dd class="dd-description"> Disable warnings in the given range.
</dd><dt class="dt-description"><span class="c019"><span class="c007">@</span><span class="c013">num1</span>..<span class="c013">num2</span></span></dt><dd class="dd-description"> Enable and mark warnings in the given range.
</dd><dt class="dt-description"><span class="c019"><span class="c007">+</span><span class="c013">letter</span></span></dt><dd class="dd-description"> Enable the set of warnings corresponding to
<span class="c013">letter</span>. The letter may be uppercase or lowercase.
</dd><dt class="dt-description"><span class="c019"><span class="c007">-</span><span class="c013">letter</span></span></dt><dd class="dd-description"> Disable the set of warnings corresponding to
<span class="c013">letter</span>. The letter may be uppercase or lowercase.
</dd><dt class="dt-description"><span class="c019"><span class="c007">@</span><span class="c013">letter</span></span></dt><dd class="dd-description"> Enable and mark the set of warnings
corresponding to <span class="c013">letter</span>. The letter may be uppercase or
lowercase.
</dd><dt class="dt-description"><span class="c017">uppercase-letter</span></dt><dd class="dd-description"> Enable the set of warnings corresponding
to <span class="c013">uppercase-letter</span>.
</dd><dt class="dt-description"><span class="c017">lowercase-letter</span></dt><dd class="dd-description"> Disable the set of warnings corresponding
to <span class="c013">lowercase-letter</span>.
</dd></dl><p>Warning numbers and letters which are out of the range of warnings
that are currently defined are ignored. The warning are as follows.
</p><dl class="description"><dt class="dt-description">
<span class="c019">1</span></dt><dd class="dd-description"> Suspicious-looking start-of-comment mark.
</dd><dt class="dt-description"><span class="c019">2</span></dt><dd class="dd-description"> Suspicious-looking end-of-comment mark.
</dd><dt class="dt-description"><span class="c019">3</span></dt><dd class="dd-description"> Deprecated feature.
</dd><dt class="dt-description"><span class="c019">4</span></dt><dd class="dd-description"> Fragile pattern matching: matching that will remain complete even
if additional constructors are added to one of the variant types
matched.
</dd><dt class="dt-description"><span class="c019">5</span></dt><dd class="dd-description"> Partially applied function: expression whose result has function
type and is ignored.
</dd><dt class="dt-description"><span class="c019">6</span></dt><dd class="dd-description"> Label omitted in function application.
</dd><dt class="dt-description"><span class="c019">7</span></dt><dd class="dd-description"> Method overridden.
</dd><dt class="dt-description"><span class="c019">8</span></dt><dd class="dd-description"> Partial match: missing cases in pattern-matching.
</dd><dt class="dt-description"><span class="c019">9</span></dt><dd class="dd-description"> Missing fields in a record pattern.
</dd><dt class="dt-description"><span class="c019">10</span></dt><dd class="dd-description"> Expression on the left-hand side of a sequence that doesn&#X2019;t have type
<span class="c007">unit</span> (and that is not a function, see warning number 5).
</dd><dt class="dt-description"><span class="c019">11</span></dt><dd class="dd-description"> Redundant case in a pattern matching (unused match case).
</dd><dt class="dt-description"><span class="c019">12</span></dt><dd class="dd-description"> Redundant sub-pattern in a pattern-matching.
</dd><dt class="dt-description"><span class="c019">13</span></dt><dd class="dd-description"> Instance variable overridden.
</dd><dt class="dt-description"><span class="c019">14</span></dt><dd class="dd-description"> Illegal backslash escape in a string constant.
</dd><dt class="dt-description"><span class="c019">15</span></dt><dd class="dd-description"> Private method made public implicitly.
</dd><dt class="dt-description"><span class="c019">16</span></dt><dd class="dd-description"> Unerasable optional argument.
</dd><dt class="dt-description"><span class="c019">17</span></dt><dd class="dd-description"> Undeclared virtual method.
</dd><dt class="dt-description"><span class="c019">18</span></dt><dd class="dd-description"> Non-principal type.
</dd><dt class="dt-description"><span class="c019">19</span></dt><dd class="dd-description"> Type without principality.
</dd><dt class="dt-description"><span class="c019">20</span></dt><dd class="dd-description"> Unused function argument.
</dd><dt class="dt-description"><span class="c019">21</span></dt><dd class="dd-description"> Non-returning statement.
</dd><dt class="dt-description"><span class="c019">22</span></dt><dd class="dd-description"> Camlp4 warning.
</dd><dt class="dt-description"><span class="c019">23</span></dt><dd class="dd-description"> Useless record <span class="c007">with</span> clause.
</dd><dt class="dt-description"><span class="c019">24</span></dt><dd class="dd-description"> Bad module name: the source file name is not a valid OCaml module name.
</dd><dt class="dt-description"><span class="c019">25</span></dt><dd class="dd-description"> Pattern-matching with all clauses guarded. Exhaustiveness cannot be
checked.
</dd><dt class="dt-description"><span class="c019">26</span></dt><dd class="dd-description"> Suspicious unused variable: unused variable that is bound
with <span class="c007">let</span> or <span class="c007">as</span>, and doesn&#X2019;t start with an underscore (<span class="c007">_</span>)
character.
</dd><dt class="dt-description"><span class="c019">27</span></dt><dd class="dd-description"> Innocuous unused variable: unused variable that is not bound with
<span class="c007">let</span> nor <span class="c007">as</span>, and doesn&#X2019;t start with an underscore (<span class="c007">_</span>)
character.
</dd><dt class="dt-description"><span class="c019">28</span></dt><dd class="dd-description"> Wildcard pattern given as argument to a constant constructor.
</dd><dt class="dt-description"><span class="c019">29</span></dt><dd class="dd-description"> Unescaped end-of-line in a string constant (non-portable code).
</dd><dt class="dt-description"><span class="c019">30</span></dt><dd class="dd-description"> Two labels or constructors of the same name are defined in two
mutually recursive types.
</dd><dt class="dt-description"><span class="c019">31</span></dt><dd class="dd-description"> A module is linked twice in the same executable.
</dd><dt class="dt-description"><span class="c019">32</span></dt><dd class="dd-description"> Unused value declaration.
</dd><dt class="dt-description"><span class="c019">33</span></dt><dd class="dd-description"> Unused open statement.
</dd><dt class="dt-description"><span class="c019">34</span></dt><dd class="dd-description"> Unused type declaration.
</dd><dt class="dt-description"><span class="c019">35</span></dt><dd class="dd-description"> Unused for-loop index.
</dd><dt class="dt-description"><span class="c019">36</span></dt><dd class="dd-description"> Unused ancestor variable.
</dd><dt class="dt-description"><span class="c019">37</span></dt><dd class="dd-description"> Unused constructor.
</dd><dt class="dt-description"><span class="c019">38</span></dt><dd class="dd-description"> Unused exception constructor.
</dd><dt class="dt-description"><span class="c019">39</span></dt><dd class="dd-description"> Unused rec flag.
</dd><dt class="dt-description"><span class="c019">40</span></dt><dd class="dd-description"> Constructor or label name used out of scope.
</dd><dt class="dt-description"><span class="c019">41</span></dt><dd class="dd-description"> Ambiguous constructor or label name.
</dd><dt class="dt-description"><span class="c019">42</span></dt><dd class="dd-description"> Disambiguated constructor or label name.
</dd><dt class="dt-description"><span class="c019">43</span></dt><dd class="dd-description"> Nonoptional label applied as optional.
</dd><dt class="dt-description"><span class="c019">44</span></dt><dd class="dd-description"> Open statement shadows an already defined identifier.
</dd><dt class="dt-description"><span class="c019">45</span></dt><dd class="dd-description"> Open statement shadows an already defined label or constructor.
</dd><dt class="dt-description"><span class="c019">A</span></dt><dd class="dd-description"> All warnings.
</dd><dt class="dt-description"><span class="c019">C</span></dt><dd class="dd-description"> Set of warnings 1, 2.
</dd><dt class="dt-description"><span class="c019">D</span></dt><dd class="dd-description"> Synonym for warning 3.
</dd><dt class="dt-description"><span class="c019">E</span></dt><dd class="dd-description"> Synonym for warning 4.
</dd><dt class="dt-description"><span class="c019">F</span></dt><dd class="dd-description"> Synonym for warning 5.
</dd><dt class="dt-description"><span class="c019">K</span></dt><dd class="dd-description"> Set of warnings 32, 33, 34, 35, 36, 37, 38, 39.
</dd><dt class="dt-description"><span class="c019">L</span></dt><dd class="dd-description"> Synonym for warning 6.
</dd><dt class="dt-description"><span class="c019">M</span></dt><dd class="dd-description"> Synonym for warning 7.
</dd><dt class="dt-description"><span class="c019">P</span></dt><dd class="dd-description"> Synonym for warning 8.
</dd><dt class="dt-description"><span class="c019">R</span></dt><dd class="dd-description"> Synonym for warning 9.
</dd><dt class="dt-description"><span class="c019">S</span></dt><dd class="dd-description"> Synonym for warning 10.
</dd><dt class="dt-description"><span class="c019">U</span></dt><dd class="dd-description"> Set of warnings 11, 12.
</dd><dt class="dt-description"><span class="c019">V</span></dt><dd class="dd-description"> Synonym for warning 13.
</dd><dt class="dt-description"><span class="c019">X</span></dt><dd class="dd-description"> Set of warnings 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 30.
</dd><dt class="dt-description"><span class="c019">Y</span></dt><dd class="dd-description"> Synonym for warning 26.
</dd><dt class="dt-description"><span class="c019">Z</span></dt><dd class="dd-description"> Synonym for warning 27.

</dd></dl><p>The default setting is <span class="c007">-w +a-4-6-7-9-27-29-32..39</span>. It is displayed by
<span class="c007">ocamlopt -help</span>.
Note that warnings 5 and 10 are not always triggered, depending on
the internals of the type checker.</p></dd><dt class="dt-description"><span class="c019"><span class="c007">-warn-error</span> <span class="c013">warning-list</span></span></dt><dd class="dd-description">
Mark as errors the warnings specified in the argument <span class="c013">warning-list</span>.
The compiler will stop with an error when one of these warnings is
emitted. The <span class="c013">warning-list</span> has the same meaning as for
the <span class="c007">-w</span> option: a <span class="c007">+</span> sign (or an uppercase letter) turns the
corresponding warnings into errors, a <span class="c007">-</span>
sign (or a lowercase letter) turns them back into warnings, and a
<span class="c007">@</span> sign both enables and marks the corresponding warnings.<p>Note: it is not recommended to use warning sets (i.e. letters) as
arguments to <span class="c007">-warn-error</span>
in production code, because this can break your build when future versions
of OCaml add some new warnings.</p><p>The default setting is <span class="c007">-warn-error -a</span>
(none of the warnings is treated as an error).</p></dd><dt class="dt-description"><span class="c010">-where</span></dt><dd class="dd-description">
Print the location of the standard library, then exit.</dd><dt class="dt-description"><span class="c019"><span class="c007">-</span> <span class="c013">file</span></span></dt><dd class="dd-description">
Process <span class="c013">file</span> as a file name, even if it starts with a dash (-)
character.</dd><dt class="dt-description"><span class="c019"><span class="c007">-help</span> or <span class="c007">--help</span></span></dt><dd class="dd-description">
Display a short usage summary and exit.
</dd></dl>
<h5 class="paragraph" id="sec261">Options for the IA32 architecture</h5>
<p>
The IA32 code generator (Intel Pentium, AMD Athlon) supports the
following additional option:</p><dl class="description"><dt class="dt-description">
<span class="c010">-ffast-math</span></dt><dd class="dd-description"> Use the IA32 instructions to compute
trigonometric and exponential functions, instead of calling the
corresponding library routines. The functions affected are:
<span class="c007">atan</span>, <span class="c007">atan2</span>, <span class="c007">cos</span>, <span class="c007">log</span>, <span class="c007">log10</span>, <span class="c007">sin</span>, <span class="c007">sqrt</span> and <span class="c007">tan</span>.
The resulting code runs faster, but the range of supported arguments
and the precision of the result can be reduced. In particular,
trigonometric operations <span class="c007">cos</span>, <span class="c007">sin</span>, <span class="c007">tan</span> have their range reduced to
[&#X2212;2<sup>64</sup>, 2<sup>64</sup>].
</dd></dl>
<h5 class="paragraph" id="sec262">Options for the AMD64 architecture</h5>
<p>
The AMD64 code generator (64-bit versions of Intel Pentium and AMD
Athlon) supports the following additional options:</p><dl class="description"><dt class="dt-description">
<span class="c010">-fPIC</span></dt><dd class="dd-description"> Generate position-independent machine code. This is
the default.
</dd><dt class="dt-description"><span class="c010">-fno-PIC</span></dt><dd class="dd-description"> Generate position-dependent machine code.
</dd></dl>
<h5 class="paragraph" id="sec263">Options for the Sparc architecture</h5>
<p>
The Sparc code generator supports the following additional options:
</p><dl class="description"><dt class="dt-description">
<span class="c010">-march=v8</span></dt><dd class="dd-description"> Generate SPARC version 8 code.
</dd><dt class="dt-description"><span class="c010">-march=v9</span></dt><dd class="dd-description"> Generate SPARC version 9 code.
</dd></dl><p>
The default is to generate code for SPARC version 7, which runs on all
SPARC processors.</p>
<h2 class="section" id="sec264">11.3&#XA0;&#XA0;Common errors</h2>
<p>The error messages are almost identical to those of <span class="c007">ocamlc</span>.
See section&#XA0;<a href="comp.html#s%3Acomp-errors">8.4</a>.</p>
<h2 class="section" id="sec265">11.4&#XA0;&#XA0;Running executables produced by ocamlopt</h2>
<p>Executables generated by <span class="c007">ocamlopt</span> are native, stand-alone executable
files that can be invoked directly. They do
not depend on the <span class="c007">ocamlrun</span> bytecode runtime system nor on
dynamically-loaded C/OCaml stub libraries.</p><p>During execution of an <span class="c007">ocamlopt</span>-generated executable,
the following environment variables are also consulted:
</p><dl class="description"><dt class="dt-description">
<span class="c010">OCAMLRUNPARAM</span></dt><dd class="dd-description"> Same usage as in <span class="c007">ocamlrun</span>
(see section&#XA0;<a href="runtime.html#ocamlrun-options">10.2</a>), except that option <span class="c007">l</span>
is ignored (the operating system&#X2019;s stack size limit
is used instead).
</dd><dt class="dt-description"><span class="c010">CAMLRUNPARAM</span></dt><dd class="dd-description"> If <span class="c007">OCAMLRUNPARAM</span> is not found in the
environment, then <span class="c007">CAMLRUNPARAM</span> will be used instead. If
<span class="c007">CAMLRUNPARAM</span> is not found, then the default values will be used.
</dd></dl>
<h2 class="section" id="sec266">11.5&#XA0;&#XA0;Compatibility with the bytecode compiler</h2>
<p>
<a id="s:compat-native-bytecode"></a></p><p>This section lists the known incompatibilities between the bytecode
compiler and the native-code compiler. Except on those points, the two
compilers should generate code that behave identically.</p><ul class="itemize"><li class="li-itemize">Signals are detected only when the program performs an
allocation in the heap. That is, if a signal is delivered while in a
piece of code that does not allocate, its handler will not be called
until the next heap allocation.</li><li class="li-itemize">Stack overflow, typically caused by excessively deep recursion,
is handled in one of the following ways, depending on the
platform used:
<ul class="itemize"><li class="li-itemize">
By raising a <span class="c007">Stack_overflow</span> exception, like the bytecode
compiler does. (IA32/Linux, AMD64/Linux, PowerPC/MacOSX, MS Windows
32-bit ports).
</li><li class="li-itemize">By aborting the program on a &#X201C;segmentation fault&#X201D; signal.
(All other Unix systems.)
</li><li class="li-itemize">By terminating the program silently.
(MS Windows 64 bits).
</li></ul></li><li class="li-itemize">On IA32 processors only (Intel and AMD x86 processors in 32-bit
mode), some intermediate results in floating-point computations are
kept in extended precision rather than being rounded to double
precision like the bytecode compiler always does. Floating-point
results can therefore differ slightly between bytecode and native code.</li></ul>
<hr>
<a href="runtime.html"><img src="previous_motif.gif" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.gif" alt="Up"></a>
<a href="lexyacc.html"><img src="next_motif.gif" alt="Next"></a>
</body>
</html>