OCaml: Tools & Ecosystem Last updated Mar 19, 2025

Compilers

Standard OCaml distributions contain no fewer than four toolchains.

bytecode binaries native binaries remarks

emit bytecode:

ocamlc.byte

ocamlc.opt

std compilers

ocamlcp.byte

ocamlcp.opt

profiling compilers

emit native code:

ocamlopt.byte

ocamlopt.opt

std compilers

ocamloptp.byte

ocamloptp.opt

profiling compilers

These are all utility commands. The actually compilers are implemented as libraries; these commands are actually drivers, like the gcc command of the GNU toolchain. They run the compilers but may also run other tools.

The *.opt versions are native code binaries; the *.byte versions are bytecode binaries, which must be executed with ocamlrun.

Runtime tracing has changed in version 5.

The profiling complers instrument the source code, adding code to record how many times functions are called, branches of conditionals are taken, etc.

By default, names without an extension are symlinked to the optimized (native) binaries:

  • ocamlc → ocamlc.opt

  • ocamlcp → ocamlcp.opt

  • ocamlopt → ocamlopt.opt

  • ocamloptp → ocamloptp.opt

By default, the OBazl rules use ocamlopt.opt: the native-code compiler binary that emits native code.

Linkage

Native-mode compilers depend on a C toolchain; they may emit and compile assembly code, and use the linker.

Bytecode-mode compilers handle everything by themselves; they do not need a linker or other C tools (unless the source code uses interop to use libraries produced by another language system (C, Rust, etc.) ?)

Other tools in the distribution

The OCaml toolchain includes a variety of tools, most of which come in *.byte and *.opt variants. Some but not all come with a man page.

  • ocaml - a toplevel system (i.e. REPL) for OCaml

  • ocamlcmt - reads a .cmt file and prints related information

  • ocamldebug - the OCaml source-level replay debugger

  • ocamldep - dependency generator: scans source files and emits dependency information

  • ocamldoc - documentation generator

  • ocamllex - lexer generator

  • ocamlmklib - generate libraries with mixed C / Caml code

  • ocamlmktop - builds OCaml toplevels that contain user code preloaded at start-up

  • ocamlobjinfo - prints information from .cmo/.cmx/.cmi files

  • ocamlprof - OCaml profiler

  • ocamlrun - executes bytecode files produced by the linking phase of the ocamlc command.

  • ocamlrund - debug version of ocamlrun

  • ocamlruni - instrumented variant of ocamlrun (see Runtime tracing with the instrumented runtime)

  • ocamlyacc - parser generator

Package managment

See Package management for more information.

OPAM

opam is the standard OCaml package manager.

ocamlfind and the findlib library

findlib is an OCaml package manager library. It has largely been supplanted by OPAM, but the metadata language it defines is used by OPAM.

ocamlfind is a commonly used command-line interface to the findlib library.

Build tools

  • Buck2 supports OCaml.

  • Dune is the most commonly used build system for OCaml. Many if not most OPAM packages use Dune.

  • ocamlbuild is the legacy build tool. It has largely been supplanted by Dune, but it is still in use.

  • omake

  • B0 is an interesting system that is used to build some popular OCaml packages.

  • oasis is another legacy tool. The last update to the repo was five years ago.

  • Makefiles are still used by many OCaml developers. The OCaml distribution uses Makefiles.

Other tools

  • codept - alternative dependency solver

  • cppo - preprocessor, modeled on the C preprocessor