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

NAME

6       ocamlc - The Objective Caml bytecode compiler
7
8
9

SYNOPSIS

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

DESCRIPTION

18       The Objective Caml bytecode compiler  ocamlc(1)  compiles  Caml  source
19       files  to  bytecode object files and link these object files to produce
20       standalone bytecode executable files.  These executable files are  then
21       run by the bytecode interpreter ocamlrun(1).
22
23       The  ocamlc(1)  command has a command-line interface similar to the one
24       of most C compilers. It accepts several types  of  arguments  and  pro‐
25       cesses them sequentially:
26
27       Arguments  ending  in .mli are taken to be source files for compilation
28       unit interfaces. Interfaces specify the names exported  by  compilation
29       units:  they  declare  value names with their types, define public data
30       types, declare abstract data types, and so on. From the file x.mli, the
31       ocamlc(1) compiler produces a compiled interface in the file x.cmi.
32
33       Arguments  ending  in  .ml are taken to be source files for compilation
34       unit implementations. Implementations provide definitions for the names
35       exported  by the unit, and also contain expressions to be evaluated for
36       their side-effects.  From the file x.ml, the  ocamlc(1)  compiler  pro‐
37       duces compiled object bytecode in the file x.cmo.
38
39       If  the interface file x.mli exists, the implementation x.ml is checked
40       against the corresponding compiled interface x.cmi, which is assumed to
41       exist.  If no interface x.mli is provided, the compilation of x.ml pro‐
42       duces a compiled interface file  x.cmi  in  addition  to  the  compiled
43       object  code  file  x.cmo.   The  file x.cmi produced corresponds to an
44       interface that exports everything that is defined in the implementation
45       x.ml.
46
47       Arguments  ending  in  .cmo  are  taken to be compiled object bytecode.
48       These files are linked together, along with the object  files  obtained
49       by  compiling  .ml  arguments  (if  any),  and  the Caml Light standard
50       library, to produce a standalone executable program. The order in which
51       .cmo  and.ml  arguments  are presented on the command line is relevant:
52       compilation units are initialized in that order at run-time, and it  is
53       a  link-time  error to use a component of a unit before having initial‐
54       ized it. Hence, a given x.cmo file must come before all .cmo files that
55       refer to the unit x.
56
57       Arguments  ending in .cma are taken to be libraries of object bytecode.
58       A library of object bytecode packs in a single file  a  set  of  object
59       bytecode  files  (.cmo  files). Libraries are built with ocamlc -a (see
60       the description of the -a option below). The object files contained  in
61       the  library are linked as regular .cmo files (see above), in the order
62       specified when the .cma file was built. The only difference is that  if
63       an 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 if the
68       -custom flag is set (see the description of -custom below).
69
70       Arguments ending in .o or .a are assumed  to  be  C  object  files  and
71       libraries. They are passed to the C linker when linking in -custom mode
72       (see the description of -custom below).
73
74       ocamlc.opt is the same  compiler  as  ocamlc,  but  compiled  with  the
75       native-code  compiler  ocamlopt(1).   Thus,  it  behaves  exactly  like
76       ocamlc, but compiles  faster.   ocamlc.opt  is  not  available  in  all
77       installations of Objective Caml.
78
79

OPTIONS

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

SEE ALSO

158       ocaml(1), ocamlrun(1).
159       The Objective Caml user's manual, chapter "Batch compilation".
160
161
162
163                                                                     OCAMLC(1)
Impressum