Your company here — click to reach over 10,000 unique daily visitors

ocamlbuild - Man Page

The OCaml project compilation tool


ocamlbuild [ -Is  dir1,... ] [ -libs lib1,... ] [ -lflags flag1,... ] [ -pp flags ] [ -tags tag1,... ] [ -j  parallel-jobs ] target.native [ -- arg1 arg2 ... ]

(same options)


ocamlbuild(1) orchestrates the compilation process of your OCaml project.  It is similar in function to make(1) except that it is tailor-made to automatically compile most OCaml projects with very little user input.

ocamlbuild should be invoked in the root of a clean project tree (e.g., with no leftover compilation files).  Given one or more targets to compile, it scans the required subdirectories to gather information about the various files present, running tools such as ocamldep(1) to extract dependency information, and gathering optional files that fine-tune its behaviour. Target names are very significant.

Target Names

ocamlbuild uses a set of target naming conventions to select the kind of objects to produce.  Target names are of the form base.extension where base is usually the name of the underlying OCaml module and extension denotes the kind of object to produce from that file -- a byte code executable, a native executable, documentation... Of course extensions such as .cmo, .cma, .cmi... map to their usual counterparts.  Here is a list of the most important ocamlbuild-specific extensions:


Native code executable


Byte code executable


Interface inferred with ocamlc-i


HTML documentation generated with ocamldoc


The following command-line options are recognized by ocamlbuild(1).


Display the version


same as -version


Display the version number


same as -vnum


Make as quiet as possible

-verbose <level>

Set the verbosity level on a scale from 0 to 8 (included)


Show rules and flags

-log <file>

Set log file


No log file


Remove build directory and other files, then exit


Traverse directories by default (true: traverse)

-I <path>

Add to include directories

-Is <path,...>

(same as above, but accepts a (comma or blank)-separated list)

-X <path>

Directory to ignore

-Xs <path,...>


-lib <flag>

Link to this ocaml library

-libs <flag,...>


-mod <module>

Link to this ocaml module

-mods <module,...>


-pkg <package>

Link to this ocaml findlib package

-pkgs <package,...>


-package <package>


-syntax <syntax>

Specify syntax using ocamlfind

-lflag <flag>

Add to ocamlc link flags

-lflags <flag,...>


-cflag <flag>

Add to ocamlc compile flags

-cflags <flag,...>


-docflag <flag>

Add to ocamldoc flags

-docflags <flag,...>


-yaccflag <flag>

Add to ocamlyacc flags

-yaccflags <flag,...>


-lexflag <flag>

Add to ocamllex flags

-lexflags <flag,...>


-ppflag <flag>

Add to ocaml preprocessing flags

-pp <flag,...>


-tag <tag>

Add to default tags

-tags <tag,...>


-plugin-tag <tag>

Use this tag when compiling the myocamlbuild.ml plugin

-plugin-tags <tag,...>


-tag-line <tag>

Use this line of tags (as in _tags)

-show-tags <path>

Show tags that applies on that pathname

-ignore <module,...>

Don't try to build these modules


Don't make links of produced final targets


Don't skip modules that are requested by ocamldep but cannot be built


Don't apply sanity-check rules


Don't build myocamlbuild.ml


Don't ignore stdlib modules


Don't catch and display exceptions (useful to display the call stack)


Just build myocamlbuild.ml


Don't use a native plugin but bytecode


Use the option only when plugin is run


Change the file name for the generated sanitization script


Do not generate sanitization script


Fail if something needs to be rebuilt


Display executed commands the old-fashioned way


Use menhir instead of ocamlyacc


Use jocaml compilers instead of ocaml ones


Use the 'ocamlfind' wrapper instead of using Findlib directly to determine command-line arguments. Use -no-ocamlfind to disable. Implies -plugin-use-ocamlfind.


Don't use ocamlfind. Implies -plugin-no-ocamlfind.


Use the 'ocamlfind' wrapper for building myocamlbuild.ml


Don't use ocamlfind for building myocamlbuild.ml

-toolchain <toolchain>

Set the Findlib toolchain to use. The default toolchain is always used for building myocamlbuild.ml.

-j <N>

Allow N jobs at once (0 for unlimited)

-build-dir <path>

Set build directory (implies no-links)

-install-lib-dir <path>

Set the install library directory

-install-bin-dir <path>

Set the install binary directory


Display the install library directory

-which <command>

Display path to the tool command

-ocamlc <command>

Set the OCaml bytecode compiler

-plugin-ocamlc <command>

Set the OCaml bytecode compiler used when building myocamlbuild.ml (only)

-ocamlopt <command>

Set the OCaml native compiler

-plugin-ocamlopt <command>

Set the OCaml native compiler used when building myocamlbuild.ml (only)

-ocamldep <command>

Set the OCaml dependency tool

-ocamldoc <command>

Set the OCaml documentation generator

-ocamlyacc <command>

Set the ocamlyacc tool

-menhir <command>

Set the menhir tool (use it after -use-menhir)

-ocamllex <command>

Set the ocamllex tool

-ocamlmklib <command>

Set the ocamlmklib tool

-ocamlmktop <command>

Set the ocamlmktop tool

-ocamlrun <command>

Set the ocamlrun tool


Stop argument processing, remaining arguments are given to the user program


Display this list of options


Display this list of options

See Also

The ocamlbuild manual, ocaml(1), make(1).
The OCaml user's manual, chapter Batch compilation .