1OCAMLOPT(1) General Commands Manual OCAMLOPT(1)
2
3
4
6 ocamlopt - The OCaml native-code compiler
7
8
10 ocamlopt [ options ] filename ...
11
12 ocamlopt.opt (same options)
13
14
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
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 Deprecated since OCaml 4.11. Please use -bin-annot instead.
100
101 -bin-annot
102 Dump detailed information about the compilation (types, bind‐
103 ings, tail-calls, etc) in binary format. The information for
104 file src.ml is put into file src.cmt. In case of a type error,
105 dump all the information inferred by the type-checker before the
106 error. The annotation files produced by -bin-annot contain more
107 information and are much more compact than the files produced by
108 -annot.
109
110 -c Compile only. Suppress the linking phase of the compilation.
111 Source code files are turned into compiled files, but no exe‐
112 cutable file is produced. This option is useful to compile mod‐
113 ules separately.
114
115 -cc ccomp
116 Use ccomp as the C linker called to build the final executable
117 and as the C compiler for compiling .c source files.
118
119 -cclib -llibname
120 Pass the -llibname option to the linker. This causes the given C
121 library to be linked with the program.
122
123 -ccopt option
124 Pass the given option to the C compiler and linker. For
125 instance, -ccopt -Ldir causes the C linker to search for C
126 libraries in directory dir.
127
128 -color mode
129 Enable or disable colors in compiler messages (especially warn‐
130 ings and errors). The following modes are supported:
131
132 auto use heuristics to enable colors only if the output supports
133 them (an ANSI-compatible tty terminal);
134
135 always enable colors unconditionally;
136
137 never disable color output.
138
139 The default setting is auto, and the current heuristic checks
140 that the "TERM" environment variable exists and is not empty or
141 "dumb", and that isatty(stderr) holds.
142
143 The environment variable "OCAML_COLOR" is considered if -color
144 is not provided. Its values are auto/always/never as above.
145
146
147 -error-style mode
148 Control the way error messages and warnings are printed. The
149 following modes are supported:
150
151 short only print the error and its location;
152
153 contextual like "short", but also display the source code snip‐
154 pet corresponding to the location of the error.
155
156 The default setting is contextual.
157
158 The environment variable "OCAML_ERROR_STYLE" is considered if
159 -error-style is not provided. Its values are short/contextual as
160 above.
161
162
163 -compact
164 Optimize the produced code for space rather than for time. This
165 results in smaller but slightly slower programs. The default is
166 to optimize for speed.
167
168 -config
169 Print the version number of ocamlopt(1) and a detailed summary
170 of its configuration, then exit.
171
172 -config-var
173 Print the value of a specific configuration variable from the
174 -config output, then exit. If the variable does not exist, the
175 exit code is non-zero.
176
177 -depend ocamldep-args
178 Compute dependencies, as ocamldep would do.
179
180 -for-pack module-path
181 Generate an object file (.cmx and .o files) that can later be
182 included as a sub-module (with the given access path) of a com‐
183 pilation unit constructed with -pack. For instance, ocam‐
184 lopt -for-pack P -c A.ml will generate a.cmx and a.o files that
185 can later be used with ocamlopt -pack -o P.cmx a.cmx.
186
187 -g Add debugging information while compiling and linking. This
188 option is required in order to produce stack backtraces when the
189 program terminates on an uncaught exception (see ocamlrun(1)).
190
191 -i Cause the compiler to print all defined names (with their
192 inferred types or their definitions) when compiling an implemen‐
193 tation (.ml file). No compiled files (.cmo and .cmi files) are
194 produced. This can be useful to check the types inferred by the
195 compiler. Also, since the output follows the syntax of inter‐
196 faces, it can help in writing an explicit interface (.mli file)
197 for a file: just redirect the standard output of the compiler to
198 a .mli file, and edit that file to remove all declarations of
199 unexported names.
200
201 -I directory
202 Add the given directory to the list of directories searched for
203 compiled interface files (.cmi), compiled object code files
204 (.cmx), and libraries (.cmxa). By default, the current directory
205 is searched first, then the standard library directory. Directo‐
206 ries added with -I are searched after the current directory, in
207 the order in which they were given on the command line, but
208 before the standard library directory. See also option -nost‐
209 dlib.
210
211 If the given directory starts with +, it is taken relative to
212 the standard library directory. For instance, -I +compiler-libs
213 adds the subdirectory compiler-libs of the standard library to
214 the search path.
215
216 -impl filename
217 Compile the file filename as an implementation file, even if its
218 extension is not .ml.
219
220 -inline n
221 Set aggressiveness of inlining to n, where n is a positive inte‐
222 ger. Specifying -inline 0 prevents all functions from being
223 inlined, except those whose body is smaller than the call site.
224 Thus, inlining causes no expansion in code size. The default
225 aggressiveness, -inline 1, allows slightly larger functions to
226 be inlined, resulting in a slight expansion in code size. Higher
227 values for the -inline option cause larger and larger functions
228 to become candidate for inlining, but can result in a serious
229 increase in code size.
230
231 -insn-sched
232 Enables the instruction scheduling pass in the compiler backend.
233
234 -intf filename
235 Compile the file filename as an interface file, even if its
236 extension is not .mli.
237
238 -intf-suffix string
239 Recognize file names ending with string as interface files
240 (instead of the default .mli).
241
242 -keep-docs
243 Keep documentation strings in generated .cmi files.
244
245 -keep-locs
246 Keep locations in generated .cmi files.
247
248 -labels
249 Labels are not ignored in types, labels may be used in applica‐
250 tions, and labelled parameters can be given in any order. This
251 is the default.
252
253 -linkall
254 Force all modules contained in libraries to be linked in. If
255 this flag is not given, unreferenced modules are not linked in.
256 When building a library (-a flag), setting the -linkall flag
257 forces all subsequent links of programs involving that library
258 to link all the modules contained in the library. When compil‐
259 ing a module (option -c), setting the -linkall option ensures
260 that this module will always be linked if it is put in a library
261 and this library is linked.
262
263 -linscan
264 Use linear scan register allocation. Compiling with this allo‐
265 cator is faster than with the usual graph coloring allocator,
266 sometimes quite drastically so for long functions and modules.
267 On the other hand, the generated code can be a bit slower.
268
269 -match-context-rows
270 Set number of rows of context used during pattern matching com‐
271 pilation. Lower values cause faster compilation, but less opti‐
272 mized code. The default value is 32.
273
274 -no-alias-deps
275 Do not record dependencies for module aliases.
276
277 -no-app-funct
278 Deactivates the applicative behaviour of functors. With this
279 option, each functor application generates new types in its
280 result and applying the same functor twice to the same argument
281 yields two incompatible structures.
282
283 -noassert
284 Do not compile assertion checks. Note that the special form
285 assert false is always compiled because it is typed specially.
286 This flag has no effect when linking already-compiled files.
287
288 -noautolink
289 When linking .cmxa libraries, ignore -cclib and -ccopt options
290 potentially contained in the libraries (if these options were
291 given when building the libraries). This can be useful if a
292 library contains incorrect specifications of C libraries or C
293 options; in this case, during linking, set -noautolink and pass
294 the correct C libraries and options on the command line.
295
296 -nodynlink
297 Allow the compiler to use some optimizations that are valid only
298 for code that is never dynlinked.
299
300 -no-insn-sched
301 Disables the instruction scheduling pass in the compiler back‐
302 end.
303
304 -nostdlib
305 Do not automatically add the standard library directory to the
306 list of directories searched for compiled interface files
307 (.cmi), compiled object code files (.cmx), and libraries
308 (.cmxa). See also option -I.
309
310 -nolabels
311 Ignore non-optional labels in types. Labels cannot be used in
312 applications, and parameter order becomes strict.
313
314 -o exec-file
315 Specify the name of the output file produced by the linker. The
316 default output name is a.out, in keeping with the Unix tradi‐
317 tion. If the -a option is given, specify the name of the library
318 produced. If the -pack option is given, specify the name of the
319 packed object file produced. If the -output-obj option is
320 given, specify the name of the output file produced. If the
321 -shared option is given, specify the name of plugin file pro‐
322 duced. This can also be used when compiling an interface or
323 implementation file, without linking, in which case it sets the
324 name of the cmi or cmo file, and also sets the module name to
325 the file name up to the first dot.
326
327 -opaque
328 When compiling a .mli interface file, this has the same effect
329 as the -opaque option of the bytecode compiler. When compiling a
330 .ml implementation file, this produces a .cmx file without
331 cross-module optimization information, which reduces recompila‐
332 tion on module change.
333
334 -open module
335 Opens the given module before processing the interface or imple‐
336 mentation files. If several -open options are given, they are
337 processed in order, just as if the statements open! module1;;
338 ... open! moduleN;; were added at the top of each file.
339
340 -output-obj
341 Cause the linker to produce a C object file instead of an exe‐
342 cutable file. This is useful to wrap OCaml code as a C library,
343 callable from any C program. The name of the output object file
344 must be set with the -o option. This option can also be used to
345 produce a compiled shared/dynamic library (.so extension).
346
347 -pack Build an object file (.cmx and .o files) and its associated com‐
348 piled interface (.cmi) that combines the .cmx object files given
349 on the command line, making them appear as sub-modules of the
350 output .cmx file. The name of the output .cmx file must be
351 given with the -o option. For instance, ocam‐
352 lopt -pack -o P.cmx A.cmx B.cmx C.cmx generates compiled files
353 P.cmx, P.o and P.cmi describing a compilation unit having three
354 sub-modules A, B and C, corresponding to the contents of the
355 object files A.cmx, B.cmx and C.cmx. These contents can be ref‐
356 erenced as P.A, P.B and P.C in the remainder of the program.
357
358 The .cmx object files being combined must have been compiled
359 with the appropriate -for-pack option. In the example above,
360 A.cmx, B.cmx and C.cmx must have been compiled with ocam‐
361 lopt -for-pack P.
362
363 Multiple levels of packing can be achieved by combining -pack
364 with -for-pack. See The OCaml user's manual, chapter "Native-
365 code compilation" for more details.
366
367 -pp command
368 Cause the compiler to call the given command as a preprocessor
369 for each source file. The output of command is redirected to an
370 intermediate file, which is compiled. If there are no compila‐
371 tion errors, the intermediate file is deleted afterwards.
372
373 -ppx command
374 After parsing, pipe the abstract syntax tree through the pre‐
375 processor command. The module Ast_mapper(3) implements the
376 external interface of a preprocessor.
377
378 -principal
379 Check information path during type-checking, to make sure that
380 all types are derived in a principal way. All programs accepted
381 in -principal mode are also accepted in default mode with equiv‐
382 alent types, but different binary signatures.
383
384 -rectypes
385 Allow arbitrary recursive types during type-checking. By
386 default, only recursive types where the recursion goes through
387 an object type are supported. Note that once you have created an
388 interface using this flag, you must use it again for all depen‐
389 dencies.
390
391 -runtime-variant suffix
392 Add suffix to the name of the runtime library that will be used
393 by the program. If OCaml was configured with option
394 -with-debug-runtime, then the d suffix is supported and gives a
395 debug version of the runtime.
396
397 -S Keep the assembly code produced during the compilation. The
398 assembly code for the source file x.ml is saved in the file x.s.
399
400 -stop-after pass
401 Stop compilation after the given compilation pass. The currently
402 supported passes are: parsing, typing.
403
404 -safe-string
405 Enforce the separation between types string and bytes, thereby
406 making strings read-only. This is the default.
407
408 -shared
409 Build a plugin (usually .cmxs) that can be dynamically loaded
410 with the Dynlink module. The name of the plugin must be set with
411 the -o option. A plugin can include a number of OCaml modules
412 and libraries, and extra native objects (.o, .a files). Build‐
413 ing native plugins is only supported for some operating system.
414 Under some systems (currently, only Linux AMD 64), all the OCaml
415 code linked in a plugin must have been compiled without the
416 -nodynlink flag. Some constraints might also apply to the way
417 the extra native objects have been compiled (under Linux AMD 64,
418 they must contain only position-independent code).
419
420 -short-paths
421 When a type is visible under several module-paths, use the
422 shortest one when printing the type's name in inferred inter‐
423 faces and error and warning messages.
424
425 -strict-sequence
426 The left-hand part of a sequence must have type unit.
427
428 -unboxed-types
429 When a type is unboxable (i.e. a record with a single argument
430 or a concrete datatype with a single constructor of one argu‐
431 ment) it will be unboxed unless annotated with [@@ocaml.boxed].
432
433 -no-unboxed-types
434 When a type is unboxable it will be boxed unless annotated with
435 [@@ocaml.unboxed]. This is the default.
436
437 -unsafe
438 Turn bound checking off for array and string accesses (the
439 v.(i)ands.[i] constructs). Programs compiled with -unsafe are
440 therefore faster, but unsafe: anything can happen if the program
441 accesses an array or string outside of its bounds. Additionally,
442 turn off the check for zero divisor in integer division and mod‐
443 ulus operations. With -unsafe, an integer division (or modulus)
444 by zero can halt the program or continue with an unspecified
445 result instead of raising a Division_by_zero exception.
446
447 -unsafe-string
448 Identify the types string and bytes, thereby making strings
449 writable. This is intended for compatibility with old source
450 code and should not be used with new software.
451
452 -v Print the version number of the compiler and the location of the
453 standard library directory, then exit.
454
455 -verbose
456 Print all external commands before they are executed, in partic‐
457 ular invocations of the assembler, C compiler, and linker.
458
459 -version or -vnum
460 Print the version number of the compiler in short form (e.g.
461 "3.11.0"), then exit.
462
463 -w warning-list
464 Enable, disable, or mark as fatal the warnings specified by the
465 argument warning-list. See ocamlc(1) for the syntax of warning-
466 list.
467
468 -warn-error warning-list
469 Mark as fatal the warnings specified in the argument warn‐
470 ing-list. The compiler will stop with an error when one of
471 these warnings is emitted. The warning-list has the same mean‐
472 ing as for the -w option: a + sign (or an uppercase letter)
473 marks the corresponding warnings as fatal, a - sign (or a lower‐
474 case letter) turns them back into non-fatal warnings, and a @
475 sign both enables and marks as fatal the corresponding warnings.
476
477 Note: it is not recommended to use the -warn-error option in
478 production code, because it will almost certainly prevent com‐
479 piling your program with later versions of OCaml when they add
480 new warnings or modify existing warnings.
481
482 The default setting is -warn-error -a+31 (only warning 31 is
483 fatal).
484
485 -warn-help
486 Show the description of all available warning numbers.
487
488 -where Print the location of the standard library, then exit.
489
490 -with-runtime
491 Include the runtime system in the generated program. This is the
492 default.
493
494 -without-runtime
495 The compiler does not include the runtime system (nor a refer‐
496 ence to it) in the generated program; it must be supplied sepa‐
497 rately.
498
499 - file Process file as a file name, even if it starts with a dash (-)
500 character.
501
502 -help or --help
503 Display a short usage summary and exit.
504
505
507 The IA32 code generator (Intel Pentium, AMD Athlon) supports the fol‐
508 lowing additional option:
509
510 -ffast-math
511 Use the IA32 instructions to compute trigonometric and exponen‐
512 tial functions, instead of calling the corresponding library
513 routines. The functions affected are: atan, atan2, cos, log,
514 log10, sin, sqrt and tan. The resulting code runs faster, but
515 the range of supported arguments and the precision of the result
516 can be reduced. In particular, trigonometric operations cos,
517 sin, tan have their range reduced to [-2^64, 2^64].
518
519
521 The AMD64 code generator (64-bit versions of Intel Pentium and AMD
522 Athlon) supports the following additional options:
523
524 -fPIC Generate position-independent machine code. This is the
525 default.
526
527 -fno-PIC
528 Generate position-dependent machine code.
529
530
532 The PowerPC code generator supports the following additional options:
533
534 -flarge-toc
535 Enables the PowerPC large model allowing the TOC (table of con‐
536 tents) to be arbitrarily large. This is the default since 4.11.
537
538 -fsmall-toc
539 Enables the PowerPC small model allowing the TOC to be up to 64
540 kbytes per compilation unit. Prior to 4.11 this was the default
541 behaviour. \nd{options}
542
543
545 The ARM code generator supports the following additional options:
546
547 -farch=armv4|armv5|armv5te|armv6|armv6t2|armv7
548 Select the ARM target architecture
549
550 -ffpu=soft|vfpv2|vfpv3-d16|vfpv3
551 Select the floating-point hardware
552
553 -fPIC Generate position-independent machine code.
554
555 -fno-PIC
556 Generate position-dependent machine code. This is the default.
557
558 -fthumb
559 Enable Thumb/Thumb-2 code generation
560
561 -fno-thumb
562 Disable Thumb/Thumb-2 code generation
563
564 The default values for target architecture, floating-point hardware and
565 thumb usage were selected at configure-time when building ocamlopt
566 itself. This configuration can be inspected using ocamlopt -config.
567 Target architecture depends on the "model" setting, while floating-
568 point hardware and thumb support are determined from the ABI setting in
569 "system" ( linux_eabiorlinux_eabihf).
570
571
573 ocamlc(1).
574 The OCaml user's manual, chapter "Native-code compilation".
575
576
577
578 OCAMLOPT(1)