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

NAME

6       ocamlopt - The OCaml native-code compiler
7
8

SYNOPSIS

10       ocamlopt [ options ] filename ...
11
12       ocamlopt.opt (same options)
13
14

DESCRIPTION

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

OPTIONS

80       The following command-line options are recognized by ocamlopt(1).
81
82       -a     Build  a  library (.cmxa/.a file) with the object files (.cmx/.o
83              files) given on the command line, instead of linking  them  into
84              an executable file. The name of the library must be set with the
85              -o option.
86
87              If -cclib or -ccopt options are  passed  on  the  command  line,
88              these  options are stored in the resulting .cmxa library.  Then,
89              linking  with  this  library   automatically   adds   back   the
90              -cclib and -ccopt  options  as  if they had been provided on the
91              command line, unless the -noautolink option is given.  Addition‐
92              ally,  a  substring $CAMLORIGIN inside a  -ccopt options will be
93              replaced by the full path to the  .cma  library,  excluding  the
94              filename.
95
96       -absname
97              Show absolute filenames in error messages.
98
99       -annot Dump  detailed  information  about the compilation (types, bind‐
100              ings, tail-calls, etc).  The information for file src.ml is  put
101              into  file  src.annot.   In  case  of a type error, dump all the
102              information inferred by the type-checker before the  error.  The
103              src.annot  file  can  be  used  with the emacs commands given in
104              emacs/caml-types.el  to  display  types  and  other  annotations
105              interactively.
106
107       -bin-annot
108              Dump  detailed  information  about the compilation (types, bind‐
109              ings, tail-calls, etc) in binary  format.  The  information  for
110              file  src.ml is put into file src.cmt.  In case of a type error,
111              dump all the information inferred by the type-checker before the
112              error.  The annotation files produced by -bin-annot contain more
113              information and are much more compact than the files produced by
114              -annot.
115
116       -c     Compile  only.  Suppress  the  linking phase of the compilation.
117              Source code files are turned into compiled files,  but  no  exe‐
118              cutable  file is produced. This option is useful to compile mod‐
119              ules separately.
120
121       -cc ccomp
122              Use ccomp as the C linker called to build the  final  executable
123              and as the C compiler for compiling .c source files.
124
125       -cclib -llibname
126              Pass the -llibname option to the linker. This causes the given C
127              library to be linked with the program.
128
129       -ccopt option
130              Pass the  given  option  to  the  C  compiler  and  linker.  For
131              instance,  -ccopt -Ldir  causes  the  C  linker  to search for C
132              libraries in directory dir.
133
134       -color mode
135              Enable or disable colors in compiler messages (especially  warn‐
136              ings and errors).  The following modes are supported:
137
138              auto use heuristics to enable colors only if the output supports
139              them (an ANSI-compatible tty terminal);
140
141              always enable colors unconditionally;
142
143              never disable color output.
144
145              The default setting is auto, and the  current  heuristic  checks
146              that  the "TERM" environment variable exists and is not empty or
147              "dumb", and that isatty(stderr) holds.
148
149              The environment variable "OCAML_COLOR" is considered  if  -color
150              is not provided. Its values are auto/always/never as above.
151
152
153       -compact
154              Optimize  the produced code for space rather than for time. This
155              results in smaller but slightly slower programs. The default  is
156              to optimize for speed.
157
158       -config
159              Print  the  version number of ocamlopt(1) and a detailed summary
160              of its configuration, then exit.
161
162       -for-pack module-path
163              Generate an object file (.cmx and .o files) that  can  later  be
164              included  as a sub-module (with the given access path) of a com‐
165              pilation unit  constructed  with  -pack.   For  instance,  ocam‐
166              lopt -for-pack P -c A.ml  will generate a.cmx and a.o files that
167              can later be used with ocamlopt -pack -o P.cmx a.cmx.
168
169       -g     Add debugging information  while  compiling  and  linking.  This
170              option is required in order to produce stack backtraces when the
171              program terminates on an uncaught exception (see ocamlrun(1)).
172
173       -i     Cause the compiler  to  print  all  defined  names  (with  their
174              inferred types or their definitions) when compiling an implemen‐
175              tation (.ml file). No compiled files (.cmo and .cmi  files)  are
176              produced.  This can be useful to check the types inferred by the
177              compiler. Also, since the output follows the  syntax  of  inter‐
178              faces,  it can help in writing an explicit interface (.mli file)
179              for a file: just redirect the standard output of the compiler to
180              a  .mli  file,  and edit that file to remove all declarations of
181              unexported names.
182
183       -I directory
184              Add the given directory to the list of directories searched  for
185              compiled  interface  files  (.cmi),  compiled  object code files
186              (.cmx), and libraries (.cmxa). By default, the current directory
187              is searched first, then the standard library directory. Directo‐
188              ries added with -I are searched after the current directory,  in
189              the  order  in  which  they  were given on the command line, but
190              before the standard library directory. See  also  option  -nost‐
191              dlib.
192
193              If  the  given  directory starts with +, it is taken relative to
194              the standard library directory. For instance,  -I +compiler-libs
195              adds  the  subdirectory compiler-libs of the standard library to
196              the search path.
197
198       -impl filename
199              Compile the file filename as an implementation file, even if its
200              extension is not .ml.
201
202       -inline n
203              Set aggressiveness of inlining to n, where n is a positive inte‐
204              ger. Specifying -inline 0  prevents  all  functions  from  being
205              inlined,  except those whose body is smaller than the call site.
206              Thus, inlining causes no expansion in  code  size.  The  default
207              aggressiveness,  -inline 1,  allows slightly larger functions to
208              be inlined, resulting in a slight expansion in code size. Higher
209              values  for the -inline option cause larger and larger functions
210              to become candidate for inlining, but can result  in  a  serious
211              increase in code size.
212
213       -intf filename
214              Compile  the  file  filename  as  an interface file, even if its
215              extension is not .mli.
216
217       -intf-suffix string
218              Recognize file names  ending  with  string  as  interface  files
219              (instead of the default .mli).
220
221       -keep-locs
222              Keep documentation strings in generated .cmi files.
223
224       -keep-locs
225              Keep locations in generated .cmi files.
226
227       -labels
228              Labels  are not ignored in types, labels may be used in applica‐
229              tions, and labelled parameters can be given in any order.   This
230              is the default.
231
232       -linkall
233              Force  all  modules  contained  in libraries to be linked in. If
234              this flag is not given, unreferenced modules are not linked  in.
235              When  building  a  library  (-a flag), setting the -linkall flag
236              forces all subsequent links of programs involving  that  library
237              to  link all the modules contained in the library.  When compil‐
238              ing a module (option -c), setting the  -linkall  option  ensures
239              that this module will always be linked if it is put in a library
240              and this library is linked.
241
242       -no-alias-deps
243              Do not record dependencies for module aliases.
244
245       -no-app-funct
246              Deactivates the applicative behaviour  of  functors.  With  this
247              option,  each  functor  application  generates  new types in its
248              result and applying the same functor twice to the same  argument
249              yields two incompatible structures.
250
251       -noassert
252              Do  not  compile  assertion  checks.  Note that the special form
253              assert false is always compiled because it is  typed  specially.
254              This flag has no effect when linking already-compiled files.
255
256       -noautolink
257              When  linking  .cmxa libraries, ignore -cclib and -ccopt options
258              potentially contained in the libraries (if  these  options  were
259              given  when  building  the  libraries).  This can be useful if a
260              library contains incorrect specifications of C  libraries  or  C
261              options;  in this case, during linking, set -noautolink and pass
262              the correct C libraries and options on the command line.
263
264       -nodynlink
265              Allow the compiler to use some optimizations that are valid only
266              for code that is never dynlinked.
267
268       -nostdlib
269              Do not automatically add the standard library directory the list
270              of directories searched for  compiled  interface  files  (.cmi),
271              compiled  object  code  files (.cmx), and libraries (.cmxa). See
272              also option -I.
273
274       -nolabels
275              Ignore non-optional labels in types. Labels cannot  be  used  in
276              applications, and parameter order becomes strict.
277
278       -o exec-file
279              Specify  the name of the output file produced by the linker. The
280              default output name is a.out, in keeping with  the  Unix  tradi‐
281              tion. If the -a option is given, specify the name of the library
282              produced. If the -pack option is given, specify the name of  the
283              packed  object  file  produced.   If  the  -output-obj option is
284              given, specify the name of the  output  file  produced.  If  the
285              -shared  option  is  given, specify the name of plugin file pro‐
286              duced.  This can also be used when  compiling  an  interface  or
287              implementation  file, without linking, in which case it sets the
288              name of the cmi or cmo file, and also sets the  module  name  to
289              the file name up to the first dot.
290
291       -opaque
292              When  compiling  a .mli interface file, this has the same effect
293              as the -opaque option of the bytecode compiler. When compiling a
294              .ml  implementation  file,  this  produces  a  .cmx file without
295              cross-module optimization information, which reduces  recompila‐
296              tion on module change.
297
298       -open module
299              Opens the given module before processing the interface or imple‐
300              mentation files. If several -open options are  given,  they  are
301              processed  in  order,  just as if the statements open! module1;;
302              ... open! moduleN;; were added at the top of each file.
303
304       -output-obj
305              Cause the linker to produce a C object file instead of  an  exe‐
306              cutable  file. This is useful to wrap OCaml code as a C library,
307              callable from any C program. The name of the output object  file
308              must be set with the -o option.  This option can also be used to
309              produce a compiled shared/dynamic library (.so extension).
310
311       -p     Generate extra code to write profile information when  the  pro‐
312              gram  is executed.  The profile information can then be examined
313              with the analysis program gprof(1).  The -p option must be given
314              both at compile-time and at link-time.  Linking object files not
315              compiled with -p is possible, but results in less  precise  pro‐
316              filing.
317
318              See  the  gprof(1)  man page for more information about the pro‐
319              files.
320
321              Full support for gprof(1) is only available  for  certain  plat‐
322              forms  (currently:  Intel x86/Linux and Alpha/Digital Unix).  On
323              other platforms, the -p option will result  in  a  less  precise
324              profile (no call graph information, only a time profile).
325
326       -pack  Build an object file (.cmx and .o files) and its associated com‐
327              piled interface (.cmi) that combines the .cmx object files given
328              on  the  command  line, making them appear as sub-modules of the
329              output .cmx file.  The name of the  output  .cmx  file  must  be
330              given    with    the    -o    option.    For   instance,   ocam‐
331              lopt -pack -o P.cmx A.cmx B.cmx C.cmx generates  compiled  files
332              P.cmx,  P.o and P.cmi describing a compilation unit having three
333              sub-modules A, B and C, corresponding to  the  contents  of  the
334              object files A.cmx, B.cmx and C.cmx.  These contents can be ref‐
335              erenced as P.A, P.B and P.C in the remainder of the program.
336
337              The .cmx object files being combined  must  have  been  compiled
338              with  the  appropriate  -for-pack option.  In the example above,
339              A.cmx, B.cmx and  C.cmx  must  have  been  compiled  with  ocam‐
340              lopt -for-pack P.
341
342              Multiple  levels  of  packing can be achieved by combining -pack
343              with -for-pack.  See The OCaml user's manual,  chapter  "Native-
344              code compilation" for more details.
345
346       -plugin plugin
347              Dynamically  load  the code of the given plugin (a .cmo, .cma or
348              .cmxs file) in the compiler. The plugin must exist in  the  same
349              kind  of  code as the compiler (ocamlopt.byte must load bytecode
350              plugins, while ocamlopt.opt must load native code plugins),  and
351              extension  adaptation  is  done automatically for .cma files (to
352              .cmxs files if the compiler is compiled in native code).
353
354       -pp command
355              Cause the compiler to call the given command as  a  preprocessor
356              for  each source file. The output of command is redirected to an
357              intermediate file, which is compiled. If there are  no  compila‐
358              tion errors, the intermediate file is deleted afterwards.
359
360       -ppx command
361              After  parsing,  pipe  the abstract syntax tree through the pre‐
362              processor command.   The  module  Ast_mapper(3)  implements  the
363              external interface of a preprocessor.
364
365       -principal
366              Check  information  path during type-checking, to make sure that
367              all types are derived in a principal way. All programs  accepted
368              in -principal mode are also accepted in default mode with equiv‐
369              alent types, but different binary signatures.
370
371       -rectypes
372              Allow  arbitrary  recursive  types  during  type-checking.    By
373              default,  only  recursive types where the recursion goes through
374              an object type are supported. Note that once you have created an
375              interface  using this flag, you must use it again for all depen‐
376              dencies.
377
378       -runtime-variant suffix
379              Add suffix to the name of the runtime library that will be  used
380              by   the   program.    If   OCaml  was  configured  with  option
381              -with-debug-runtime, then the d suffix is supported and gives  a
382              debug version of the runtime.
383
384       -S     Keep  the  assembly  code  produced  during the compilation. The
385              assembly code for the source file x.ml is saved in the file x.s.
386
387       -safe-string
388              Enforce the separation between types  string and bytes,  thereby
389              making  strings  read-only.  This  will  become the default in a
390              future version of OCaml.
391
392       -shared
393              Build a plugin (usually .cmxs) that can  be  dynamically  loaded
394              with the Dynlink module. The name of the plugin must be set with
395              the -o option. A plugin can include a number  of  OCaml  modules
396              and  libraries, and extra native objects (.o, .a files).  Build‐
397              ing native plugins is only supported for some operating  system.
398              Under some systems (currently, only Linux AMD 64), all the OCaml
399              code linked in a plugin must  have  been  compiled  without  the
400              -nodynlink  flag.  Some  constraints might also apply to the way
401              the extra native objects have been compiled (under Linux AMD 64,
402              they must contain only position-independent code).
403
404       -short-paths
405              When  a  type  is  visible  under  several module-paths, use the
406              shortest one when printing the type's name  in  inferred  inter‐
407              faces and error and warning messages.
408
409       -strict-sequence
410              The left-hand part of a sequence must have type unit.
411
412       -thread
413              Compile  or link multithreaded programs, in combination with the
414              system threads library described in The OCaml user's manual.
415
416       -unboxed-types
417              When a type is unboxable (i.e. a record with a  single  argument
418              or  a  concrete  datatype with a single constructor of one argu‐
419              ment) it will be unboxed unless annotated with [@@ocaml.boxed].
420
421       -no-unboxed-types
422              When a type is unboxable  it will be boxed unless annotated with
423              [@@ocaml.unboxed].  This is the default.
424
425       -unsafe
426              Turn  bound  checking  off  for  array  and string accesses (the
427              v.(i)ands.[i] constructs). Programs compiled  with  -unsafe  are
428              therefore faster, but unsafe: anything can happen if the program
429              accesses an array or string outside of its bounds. Additionally,
430              turn off the check for zero divisor in integer division and mod‐
431              ulus operations.  With -unsafe, an integer division (or modulus)
432              by  zero  can  halt  the program or continue with an unspecified
433              result instead of raising a Division_by_zero exception.
434
435       -unsafe-string
436              Identify the  types  string and bytes,  thereby  making  strings
437              writable.  For  reasons  of  backward compatibility, this is the
438              default setting for the moment, but this will change in a future
439              version of OCaml.
440
441       -v     Print the version number of the compiler and the location of the
442              standard library directory, then exit.
443
444       -verbose
445              Print all external commands before they are executed, in partic‐
446              ular invocations of the assembler, C compiler, and linker.
447
448       -version or -vnum
449              Print  the  version  number  of the compiler in short form (e.g.
450              "3.11.0"), then exit.
451
452       -w warning-list
453              Enable, disable, or mark as fatal the warnings specified by  the
454              argument warning-list.  See ocamlc(1) for the syntax of warning-
455              list.
456
457       -warn-error warning-list
458              Mark as fatal the  warnings  specified  in  the  argument  warn‐
459              ing-list.   The  compiler  will  stop  with an error when one of
460              these warnings is emitted.  The warning-list has the same  mean‐
461              ing  as  for  the  -w  option: a + sign (or an uppercase letter)
462              marks the corresponding warnings as fatal, a - sign (or a lower‐
463              case  letter)  turns  them back into non-fatal warnings, and a @
464              sign both enables and marks as fatal the corresponding warnings.
465
466              Note: it is not recommended to use  the  -warn-error  option  in
467              production  code,  because it will almost certainly prevent com‐
468              piling your program with later versions of OCaml when  they  add
469              new warnings or modify existing warnings.
470
471              The  default  setting  is  -warn-error -a+31 (only warning 31 is
472              fatal).
473
474       -warn-help
475              Show the description of all available warning numbers.
476
477       -where Print the location of the standard library, then exit.
478
479       - file Process file as a file name, even if it starts with a  dash  (-)
480              character.
481
482       -help or --help
483              Display a short usage summary and exit.
484
485

OPTIONS FOR THE IA32 ARCHITECTURE

487       The  IA32  code generator (Intel Pentium, AMD Athlon) supports the fol‐
488       lowing additional option:
489
490       -ffast-math
491              Use the IA32 instructions to compute trigonometric and  exponen‐
492              tial  functions,  instead  of  calling the corresponding library
493              routines.  The functions affected are: atan,  atan2,  cos,  log,
494              log10,  sin,  sqrt and tan.  The resulting code runs faster, but
495              the range of supported arguments and the precision of the result
496              can  be  reduced.   In particular, trigonometric operations cos,
497              sin, tan have their range reduced to [-2^64, 2^64].
498
499

OPTIONS FOR THE AMD64 ARCHITECTURE

501       The AMD64 code generator (64-bit versions  of  Intel  Pentium  and  AMD
502       Athlon) supports the following additional options:
503
504       -fPIC  Generate   position-independent   machine  code.   This  is  the
505              default.
506
507       -fno-PIC
508              Generate position-dependent machine code.
509
510

OPTIONS FOR THE SPARC ARCHITECTURE

512       The Sparc code generator supports the following additional options:
513
514       -march=v8
515              Generate SPARC version 8 code.
516
517       -march=v9
518              Generate SPARC version 9 code.
519
520       The default is to generate code for SPARC version 7, which runs on  all
521       SPARC processors.
522
523

OPTIONS FOR THE ARM ARCHITECTURE

525       The ARM code generator supports the following additional options:
526
527       -farch=armv4|armv5|armv5te|armv6|armv6t2|armv7
528              Select the ARM target architecture
529
530       -ffpu=soft|vfpv2|vfpv3-d16|vfpv3
531              Select the floating-point hardware
532
533       -fPIC  Generate position-independent machine code.
534
535       -fno-PIC
536              Generate position-dependent machine code.  This is the default.
537
538       -fthumb
539              Enable Thumb/Thumb-2 code generation
540
541       -fno-thumb
542              Disable Thumb/Thumb-2 code generation
543
544       The default values for target architecture, floating-point hardware and
545       thumb usage were selected  at  configure-time  when  building  ocamlopt
546       itself.  This  configuration  can  be inspected using ocamlopt -config.
547       Target architecture depends on the  "model"  setting,  while  floating-
548       point hardware and thumb support are determined from the ABI setting in
549       "system" ( linux_eabiorlinux_eabihf).
550
551

SEE ALSO

553       ocamlc(1).
554       The OCaml user's manual, chapter "Native-code compilation".
555
556
557
558                                                                   OCAMLOPT(1)
Impressum