]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml/contrib/man/ocamlc.m
Update
[l4.git] / l4 / pkg / ocaml / ocaml / contrib / man / ocamlc.m
1 \" $Id: ocamlc.m 9111 2008-10-29 12:38:52Z doligez $
2
3 .TH OCAMLC 1
4
5 .SH NAME
6 ocamlc \- The Objective Caml bytecode compiler
7
8 .SH SYNOPSIS
9 .B ocamlc
10 [
11 .I options
12 ]
13 .I filename ...
14
15 .B ocamlc.opt
16 [
17 .I options
18 ]
19 .I filename ...
20
21 .SH DESCRIPTION
22
23 The Objective Caml bytecode compiler
24 .BR ocamlc (1)
25 compiles Caml source files to bytecode object files and links
26 these object files to produce standalone bytecode executable files.
27 These executable files are then run by the bytecode interpreter
28 .BR ocamlrun (1).
29
30 The
31 .BR ocamlc (1)
32 command has a command-line interface similar to the one of
33 most C compilers. It accepts several types of arguments and processes them
34 sequentially:
35
36 Arguments ending in .mli are taken to be source files for
37 compilation unit interfaces. Interfaces specify the names exported by
38 compilation units: they declare value names with their types, define
39 public data types, declare abstract data types, and so on. From the
40 file
41 .IR x \&.mli,
42 the
43 .BR ocamlc (1)
44 compiler produces a compiled interface
45 in the file
46 .IR x \&.cmi.
47
48 Arguments ending in .ml are taken to be source files for compilation
49 unit implementations. Implementations provide definitions for the
50 names exported by the unit, and also contain expressions to be
51 evaluated for their side-effects.  From the file
52 .IR x \&.ml,
53 the
54 .BR ocamlc (1)
55 compiler produces compiled object bytecode in the file
56 .IR x \&.cmo.
57
58 If the interface file
59 .IR x \&.mli
60 exists, the implementation
61 .IR x \&.ml
62 is checked against the corresponding compiled interface
63 .IR x \&.cmi,
64 which is assumed to exist. If no interface
65 .IR x \&.mli
66 is provided, the compilation of
67 .IR x \&.ml
68 produces a compiled interface file
69 .IR x \&.cmi
70 in addition to the compiled object code file
71 .IR x \&.cmo.
72 The file
73 .IR x \&.cmi
74 produced
75 corresponds to an interface that exports everything that is defined in
76 the implementation
77 .IR x \&.ml.
78
79 Arguments ending in .cmo are taken to be compiled object bytecode.  These
80 files are linked together, along with the object files obtained
81 by compiling .ml arguments (if any), and the Caml Light standard
82 library, to produce a standalone executable program. The order in
83 which .cmo and.ml arguments are presented on the command line is
84 relevant: compilation units are initialized in that order at
85 run-time, and it is a link-time error to use a component of a unit
86 before having initialized it. Hence, a given
87 .IR x \&.cmo
88 file must come before all .cmo files that refer to the unit
89 .IR x .
90
91 Arguments ending in .cma are taken to be libraries of object bytecode.
92 A library of object bytecode packs in a single file a set of object
93 bytecode files (.cmo files). Libraries are built with
94 .B ocamlc\ \-a
95 (see the description of the
96 .B \-a
97 option below). The object files
98 contained in the library are linked as regular .cmo files (see above),
99 in the order specified when the .cma file was built. The only
100 difference is that if an object file
101 contained in a library is not referenced anywhere in the program, then
102 it is not linked in.
103
104 Arguments ending in .c are passed to the C compiler, which generates
105 a .o object file. This object file is linked with the program if the
106 .B \-custom
107 flag is set (see the description of
108 .B \-custom
109 below).
110
111 Arguments ending in .o or .a are assumed to be C object files and
112 libraries. They are passed to the C linker when linking in
113 .B \-custom
114 mode (see the description of
115 .B \-custom
116 below).
117
118 Arguments ending in .so
119 are assumed to be C shared libraries (DLLs).  During linking, they are
120 searched for external C functions referenced from the Caml code,
121 and their names are written in the generated bytecode executable.
122 The run-time system
123 .BR ocamlrun (1)
124 then loads them dynamically at program start-up time.
125
126 The output of the linking phase is a file containing compiled bytecode
127 that can be executed by the Objective Caml bytecode interpreter:
128 the command
129 .BR ocamlrun (1).
130 If
131 .B caml.out
132 is the name of the file produced by the linking phase, the command
133 .B ocamlrun caml.out
134 .IR arg1 \  \ arg2 \ ... \ argn
135 executes the compiled code contained in
136 .BR caml.out ,
137 passing it as arguments the character strings
138 .I arg1
139 to
140 .IR argn .
141 (See
142 .BR ocamlrun (1)
143 for more details.)
144
145 On most systems, the file produced by the linking
146 phase can be run directly, as in:
147 .B ./caml.out
148 .IR arg1 \  \ arg2 \ ... \ argn .
149 The produced file has the executable bit set, and it manages to launch
150 the bytecode interpreter by itself.
151
152 .B ocamlc.opt
153 is the same compiler as
154 .BR ocamlc ,
155 but compiled with the native-code compiler
156 .BR ocamlopt (1).
157 Thus, it behaves exactly like
158 .BR ocamlc ,
159 but compiles faster.
160 .B ocamlc.opt
161 may not be available in all installations of Objective Caml.
162
163 .SH OPTIONS
164
165 The following command-line options are recognized by
166 .BR ocamlc (1).
167 .TP
168 .B \-a
169 Build a library (.cma file) with the object files (.cmo files) given
170 on the command line, instead of linking them into an executable
171 file. The name of the library must be set with the
172 .B \-o
173 option.
174 .IP
175 If
176 .BR \-custom , \ \-cclib \ or \ \-ccopt
177 options are passed on the command
178 line, these options are stored in the resulting .cma library.  Then,
179 linking with this library automatically adds back the
180 .BR \-custom , \ \-cclib \ and \ \-ccopt
181 options as if they had been provided on the
182 command line, unless the
183 .B -noautolink
184 option is given.
185 .TP
186 .B \-annot
187 Dump detailed information about the compilation (types, bindings,
188 tail-calls, etc).  The information for file
189 .IR src .ml
190 is put into file
191 .IR src .annot.
192 In case of a type error, dump all the information inferred by the
193 type-checker before the error. The
194 .IR src .annot
195 file can be used with the emacs commands given in
196 .B emacs/caml\-types.el
197 to display types and other annotations interactively.
198 .TP
199 .B \-c
200 Compile only. Suppress the linking phase of the
201 compilation. Source code files are turned into compiled files, but no
202 executable file is produced. This option is useful to
203 compile modules separately.
204 .TP
205 .BI \-cc \ ccomp
206 Use
207 .I ccomp
208 as the C linker when linking in "custom runtime" mode (see the
209 .B \-custom
210 option) and as the C compiler for compiling .c source files.
211 .TP
212 .BI \-cclib\ -l libname
213 Pass the
214 .BI \-l libname
215 option to the C linker when linking in "custom runtime" mode (see the
216 .B \-custom
217 option). This causes the given C library to be linked with the program.
218 .TP
219 .B \-ccopt
220 Pass the given option to the C compiler and linker, when linking in
221 "custom runtime" mode (see the
222 .B \-custom
223 option). For instance,
224 .BI \-ccopt\ \-L dir
225 causes the C linker to search for C libraries in
226 directory
227 .IR dir .
228 .TP
229 .B \-config
230 Print the version number of
231 .BR ocamlc (1)
232 and a detailed summary of its configuration, then exit.
233 .TP
234 .B \-custom
235 Link in "custom runtime" mode. In the default linking mode, the
236 linker produces bytecode that is intended to be executed with the
237 shared runtime system,
238 .BR ocamlrun (1).
239 In the custom runtime mode, the
240 linker produces an output file that contains both the runtime system
241 and the bytecode for the program. The resulting file is larger, but it
242 can be executed directly, even if the
243 .BR ocamlrun (1)
244 command is not
245 installed. Moreover, the "custom runtime" mode enables linking Caml
246 code with user-defined C functions.
247
248 Never use the
249 .BR strip (1)
250 command on executables produced by
251 .BR ocamlc\ \-custom ,
252 this would remove the bytecode part of the executable.
253 .TP
254 .BI \-dllib\ \-l libname
255 Arrange for the C shared library
256 .BI dll libname .so
257 to be loaded dynamically by the run-time system
258 .BR ocamlrun (1)
259 at program start-up time.
260 .TP
261 .BI \-dllpath \ dir
262 Adds the directory
263 .I dir
264 to the run-time search path for shared
265 C libraries.  At link-time, shared libraries are searched in the
266 standard search path (the one corresponding to the
267 .B \-I
268 option).
269 The
270 .B \-dllpath
271 option simply stores
272 .I dir
273 in the produced
274 executable file, where
275 .BR ocamlrun (1)
276 can find it and use it.
277 .TP
278 .B \-g
279 Add debugging information while compiling and linking. This option is
280 required in order to be able to debug the program with
281 .BR ocamldebug (1)
282 and to produce stack backtraces when
283 the program terminates on an uncaught exception.
284 .TP
285 .B \-i
286 Cause the compiler to print all defined names (with their inferred
287 types or their definitions) when compiling an implementation (.ml
288 file). No compiled files (.cmo and .cmi files) are produced.
289 This can be useful to check the types inferred by the
290 compiler. Also, since the output follows the syntax of interfaces, it
291 can help in writing an explicit interface (.mli file) for a file: just
292 redirect the standard output of the compiler to a .mli file, and edit
293 that file to remove all declarations of unexported names.
294 .TP
295 .BI \-I \ directory
296 Add the given directory to the list of directories searched for
297 compiled interface files (.cmi), compiled object code files
298 (.cmo), libraries (.cma), and C libraries specified with
299 .B \-cclib\ \-l
300 .IR xxx .
301 By default, the current directory is searched first, then the
302 standard library directory. Directories added with
303 .B -I
304 are searched
305 after the current directory, in the order in which they were given on
306 the command line, but before the standard library directory.
307
308 If the given directory starts with
309 .BR + ,
310 it is taken relative to the
311 standard library directory. For instance,
312 .B \-I\ +labltk
313 adds the subdirectory
314 .B labltk
315 of the standard library to the search path.
316 .TP
317 .BI \-impl \ filename
318 Compile the file
319 .I filename
320 as an implementation file, even if its extension is not .ml.
321 .TP
322 .BI \-intf \ filename
323 Compile the file
324 .I filename
325 as an interface file, even if its extension is not .mli.
326 .TP
327 .BI \-intf\-suffix \ string
328 Recognize file names ending with
329 .I string
330 as interface files (instead of the default .mli).
331 .TP
332 .B \-labels
333 Labels are not ignored in types, labels may be used in applications,
334 and labelled parameters can be given in any order.  This is the default.
335 .TP
336 .B \-linkall
337 Force all modules contained in libraries to be linked in. If this
338 flag is not given, unreferenced modules are not linked in. When
339 building a library (option
340 .BR \-a ),
341 setting the
342 .B \-linkall
343 option forces all subsequent links of programs involving that library
344 to link all the modules contained in the library.
345 .TP
346 .B \-make\-runtime
347 Build a custom runtime system (in the file specified by option
348 .BR \-o )
349 incorporating the C object files and libraries given on the command
350 line.  This custom runtime system can be used later to execute
351 bytecode executables produced with the option
352 .B ocamlc\ \-use\-runtime
353 .IR runtime-name .
354 .TP
355 .B \-noassert
356 Do not compile assertion checks.  Note that the special form
357 .B assert\ false
358 is always compiled because it is typed specially.
359 This flag has no effect when linking already-compiled files.
360 .TP
361 .B \-noautolink
362 When linking .cma libraries, ignore
363 .BR \-custom , \ \-cclib \ and \ \-ccopt
364 options potentially contained in the libraries (if these options were
365 given when building the libraries).  This can be useful if a library
366 contains incorrect specifications of C libraries or C options; in this
367 case, during linking, set
368 .B \-noautolink
369 and pass the correct C libraries and options on the command line.
370 .TP
371 .B \-nolabels
372 Ignore non-optional labels in types. Labels cannot be used in
373 applications, and parameter order becomes strict.
374 .TP
375 .BI \-o \ exec\-file
376 Specify the name of the output file produced by the linker. The
377 default output name is
378 .BR a.out ,
379 in keeping with the Unix tradition. If the
380 .B \-a
381 option is given, specify the name of the library
382 produced.  If the
383 .B \-pack
384 option is given, specify the name of the
385 packed object file produced.  If the
386 .B \-output\-obj
387 option is given,
388 specify the name of the output file produced.
389 .TP
390 .B \-output\-obj
391 Cause the linker to produce a C object file instead of a bytecode
392 executable file. This is useful to wrap Caml code as a C library,
393 callable from any C program. The name of the output object file is
394 .B camlprog.o
395 by default; it can be set with the
396 .B \-o
397 option. This
398 option can also be used to produce a C source file (.c extension) or
399 a compiled shared/dynamic library (.so extension).
400 .TP
401 .B \-pack
402 Build a bytecode object file (.cmo file) and its associated compiled
403 interface (.cmi) that combines the object
404 files given on the command line, making them appear as sub-modules of
405 the output .cmo file.  The name of the output .cmo file must be
406 given with the
407 .B \-o
408 option.  For instance,
409 .B ocamlc\ \-pack\ \-o\ p.cmo\ a.cmo\ b.cmo\ c.cmo
410 generates compiled files p.cmo and p.cmi describing a compilation
411 unit having three sub-modules A, B and C, corresponding to the
412 contents of the object files a.cmo, b.cmo and c.cmo.  These
413 contents can be referenced as P.A, P.B and P.C in the remainder
414 of the program.
415 .TP
416 .BI \-pp \ command
417 Cause the compiler to call the given
418 .I command
419 as a preprocessor for each source file. The output of
420 .I command
421 is redirected to
422 an intermediate file, which is compiled. If there are no compilation
423 errors, the intermediate file is deleted afterwards. The name of this
424 file is built from the basename of the source file with the extension .ppi
425 for an interface (.mli) file and .ppo for an implementation
426 (.ml) file.
427 .TP
428 .B \-principal
429 Check information path during type-checking, to make sure that all
430 types are derived in a principal way.  When using labelled arguments
431 and/or polymorphic methods, this flag is required to ensure future
432 versions of the compiler will be able to infer types correctly, even
433 if internal algorithms change.
434 All programs accepted in
435 .B \-principal
436 mode are also accepted in the
437 default mode with equivalent types, but different binary signatures,
438 and this may slow down type checking; yet it is a good idea to
439 use it once before publishing source code.
440 .TP
441 .B \-rectypes
442 Allow arbitrary recursive types during type-checking.  By default,
443 only recursive types where the recursion goes through an object type
444 are supported. Note that once you have created an interface using this
445 flag, you must use it again for all dependencies.
446 .TP
447 .B \-thread
448 Compile or link multithreaded programs, in combination with the
449 system "threads" library described in
450 .IR The\ Objective\ Caml\ user's\ manual .
451 .TP
452 .B \-unsafe
453 Turn bound checking off for array and string accesses (the
454 .BR v.(i) and s.[i]
455 constructs). Programs compiled with
456 .B \-unsafe
457 are therefore
458 slightly faster, but unsafe: anything can happen if the program
459 accesses an array or string outside of its bounds.
460 .TP
461 .BI \-use\-runtime \ runtime\-name
462 Generate a bytecode executable file that can be executed on the custom
463 runtime system
464 .IR runtime\-name ,
465 built earlier with
466 .B ocamlc\ \-make\-runtime
467 .IR runtime\-name .
468 .TP
469 .B \-v
470 Print the version number of the compiler and the location of the
471 standard library directory, then exit.
472 .TP
473 .B \-verbose
474 Print all external commands before they are executed, in particular
475 invocations of the C compiler and linker in
476 .B \-custom
477 mode.  Useful to debug C library problems.
478 .TP
479 .B \-version
480 Print the version number of the compiler in short form (e.g. "3.11.0"),
481 then exit.
482 .TP
483 .B \-vmthread
484 Compile or link multithreaded programs, in combination with the
485 VM-level threads library described in
486 .IR The\ Objective\ Caml\ user's\ manual .
487 .TP
488 .BI \-w \ warning\-list
489 Enable or disable warnings according to the argument
490 .IR warning\-list .
491 The argument is a set of letters.  If a letter is
492 uppercase, it enables the corresponding warnings; lowercase disables
493 the warnings.  The correspondence is the following:
494
495 .B A
496 \ \ all warnings
497
498 .B C
499 \ \ start of comments that look like mistakes
500
501 .B D
502 \ \ use of deprecated features
503
504 .B E
505 \ \ fragile pattern matchings (matchings that will remain
506 complete even if additional constructors are added to one of the
507 variant types matched)
508
509 .B F
510 \ \ partially applied functions (expressions whose result has
511 function type and is ignored)
512
513 .B L
514 \ \ omission of labels in applications
515
516 .B M
517 \ \ overriding of methods
518
519 .B P
520 \ \ missing cases in pattern matchings (i.e. partial matchings)
521
522 .B S
523 \ \ expressions in the left-hand side of a sequence that don't
524 have type
525 .B unit
526 (and that are not functions, see
527 .B F
528 above)
529
530 .B U
531 \ \ redundant cases in pattern matching (unused cases)
532
533 .B V
534 \ \ overriding of instance variables
535
536 .B Y
537 \ \ unused variables that are bound with
538 .BR let \ or \ as ,
539 and don't start with an underscore (_) character
540
541 .B Z
542 \ \ all other cases of unused variables that don't start with an
543 underscore (_) character
544
545 .B X
546 \ \ warnings that don't fit in the above categories (except
547 .BR A )
548 .IP
549 The default setting is
550 .BR \-w\ Aelz ,
551 enabling all warnings except fragile
552 pattern matchings, omitted labels, and innocuous unused variables.
553 Note that warnings
554 .BR F \ and \ S
555 are not always triggered, depending on the internals of the type checker.
556 .TP
557 .BI \-warn\-error \ warning\-list
558 Turn the warnings indicated in the argument
559 .I warning\-list
560 into errors.  The compiler will stop with an error when one of these
561 warnings is emitted.  The
562 .I warning\-list
563 has the same meaning as for
564 the "\-w" option: an uppercase character turns the corresponding
565 warning into an error, a lowercase character leaves it as a warning.
566 The default setting is
567 .B \-warn\-error\ a
568 (none of the warnings is treated as an error).
569 .TP
570 .B \-where
571 Print the location of the standard library, then exit.
572 .TP
573 .BI \- \ file
574 Process
575 .I file
576 as a file name, even if it starts with a dash (-) character.
577 .TP
578 .BR \-help \ or \ \-\-help
579 Display a short usage summary and exit.
580
581 .SH SEE ALSO
582 .BR ocamlopt (1), \ ocamlrun (1), \ ocaml (1).
583 .br
584 .IR "The Objective Caml user's manual" ,
585 chapter "Batch compilation".