1OCAMLOPT(1)                 General Commands Manual                OCAMLOPT(1)
2
3
4

NAME

6       ocamlopt - The Objective Caml native-code compiler
7
8
9

SYNOPSIS

11       ocamlopt [ -acivS ] [ -cclib libname ] [ -ccopt option ] [ -compact ] [
12       -unsafe ] [ -o exec-file ] [ -I lib-dir ] filename ...
13
14       ocamlopt.opt (same options)
15
16

DESCRIPTION

18       The Objective Caml high-performance  native-code  compiler  ocamlopt(1)
19       compiles  Caml  source files to native code object files and link these
20       object files to produce standalone executables.
21
22       The ocamlopt(1) command has a command-line interface very close to that
23       of  ocamlc(1).   It  accepts  the same types of arguments and processes
24       them sequentially:
25
26       Arguments ending in .mli are taken to be source files  for  compilation
27       unit  interfaces.  Interfaces specify the names exported by compilation
28       units: they declare value names with their types,  define  public  data
29       types, declare abstract data types, and so on. From the file x.mli, the
30       ocamlopt(1) compiler produces a compiled interface in the  file  x.cmi.
31       The  interface  produced  is identical to that produced by the bytecode
32       compiler ocamlc(1).
33
34       Arguments ending in .ml are taken to be source  files  for  compilation
35       unit implementations. Implementations provide definitions for the names
36       exported by the unit, and also contain expressions to be evaluated  for
37       their  side-effects.  From the file x.ml, the ocamlopt(1) compiler pro‐
38       duces two files: x.o, containing native object code,  and  x.cmx,  con‐
39       taining  extra  information for linking and optimization of the clients
40       of the unit. The compiled implementation should always be  referred  to
41       under the name x.cmx (when given a .o file, ocamlopt(1) assumes that it
42       contains code compiled from C, not from Caml).
43
44       The implementation is checked against the interface file x.mli  (if  it
45       exists) as described in the manual for ocamlc(1).
46
47       Arguments  ending  in .cmx are taken to be compiled object code.  These
48       files are linked together, along with the object files obtained by com‐
49       piling  .ml arguments (if any), and the Caml Light standard library, to
50       produce a native-code executable program. The order in which  .cmx  and
51       .ml  arguments  are presented on the command line is relevant: compila‐
52       tion units are initialized in that order at run-time, and it is a link-
53       time  error  to use a component of a unit before having initialized it.
54       Hence, a given x.cmx file must come before all .cmx files that refer to
55       the unit x.
56
57       Arguments  ending  in  .cmxa  are taken to be libraries of object code.
58       Such a library packs in two files lib.cmxa and lib.a a  set  of  object
59       files  (.cmx/.o  files).  Libraries are build with ocamlopt -a (see the
60       description of the -a option below). The object files contained in  the
61       library  are  linked  as  regular  .cmx files (see above), in the order
62       specified when the library was built. The only difference is that if an
63       object  file  contained  in a library is not referenced anywhere in the
64       program, then it is not linked in.
65
66       Arguments ending in .c are passed to the C compiler, which generates  a
67       .o object file. This object file is linked with the program.
68
69       Arguments  ending  in  .o  or  .a  are assumed to be C object files and
70       libraries. They are linked with the program.
71
72       The output of the linking phase is a regular Unix executable  file.  It
73       does not need ocamlrun(1) to run.
74
75       ocamlopt.opt is the same compiler as ocamlopt, but compiled with itself
76       instead of with the bytecode  compiler  ocamlc(1).   Thus,  it  behaves
77       exactly like ocamlopt, but compiles faster.  ocamlopt.opt is not avail‐
78       able in all installations of Objective Caml.
79
80

OPTIONS

82       The following command-line options are recognized by ocamlopt(1).
83
84
85       -a     Build a library (.cmxa/.a file) with the object  files  (.cmx/.o
86              files)  given  on the command line, instead of linking them into
87              an executable file. The name of the library can be set with  the
88              -o option. The default name is library.cmxa.
89
90
91       -c     Compile  only.  Suppress  the  linking phase of the compilation.
92              Source code files are turned into compiled files,  but  no  exe‐
93              cutable  file is produced. This option is useful to compile mod‐
94              ules separately.
95
96
97       -cclib -llibname
98              Pass the -llibname option to the linker. This causes the given C
99              library to be linked with the program.
100
101
102       -ccopt option
103              Pass  the  given  option  to  the  C  compiler  and  linker. For
104              instance, -ccopt -L dir causes the C  linker  to  search  for  C
105              libraries in directory dir.
106
107
108       -compact
109              Optimize  the produced code for space rather than for time. This
110              results in smaller but slightly slower programs. The default  is
111              to optimize for speed.
112
113
114       -i     Cause  the  compiler  to  print  all  defined  names (with their
115              inferred types or their definitions) when compiling an implemen‐
116              tation  (.ml  file).  This  can  be  useful  to  check the types
117              inferred by the compiler. Also, since  the  output  follows  the
118              syntax  of interfaces, it can help in writing an explicit inter‐
119              face (.mli file) for a file: just redirect the  standard  output
120              of the compiler to a .mli file, and edit that file to remove all
121              declarations of unexported names.
122
123
124       -I directory
125              Add the given directory to the list of directories searched  for
126              compiled  interface  files (.cmi) and compiled object code files
127              (.cmo). By default, the current  directory  is  searched  first,
128              then  the  standard library directory. Directories added with -I
129              are searched after the current directory, in the order in  which
130              they  were  given  on  the command line, but before the standard
131              library directory.
132
133
134       -o exec-file
135              Specify the name of the output file produced by the linker.  The
136              default  output  name  is a.out, in keeping with the Unix tradi‐
137              tion. If the -a option is given, specify the name of the library
138              produced.
139
140
141       -S     Keep  the  assembly  code  produced  during the compilation. The
142              assembly code for the source file x.ml is saved in the file x.s.
143
144
145       -v     Print the version number of the compiler.
146
147
148       -unsafe
149              Turn bound checking off on array and string accesses (the  v.(i)
150              and s.[i] constructs). Programs compiled with -unsafe are there‐
151              fore faster, but unsafe: anything  can  happen  if  the  program
152              accesses an array or string outside of its bounds.
153
154

SEE ALSO

156       ocamlc(1).
157       The Objective Caml user's manual, chapter "Native-code compilation".
158
159
160
161                                                                   OCAMLOPT(1)
Impressum