ocamlc

OCaml bytecode compiler

TLDR

Compile to bytecode
$ ocamlc -o [program] [source.ml]
Compile multiple files
$ ocamlc -o [program] [file1.ml] [file2.ml]
Compile with library
$ ocamlc -I +[library] [library].cma [source.ml] -o [program]
Compile to object file
$ ocamlc -c [source.ml]
Compile with debug info
$ ocamlc -g -o [program] [source.ml]

SYNOPSIS

ocamlc [options] files...

DESCRIPTION

ocamlc is the OCaml bytecode compiler. It compiles OCaml source files to bytecode that runs on the OCaml virtual machine.For native code compilation with better performance, use ocamlopt instead.

PARAMETERS

-o file

Output filename.
-c
Compile only (no link).
-I dir
Add include directory.
-g
Include debug info.
-i
Print inferred types.
-a
Create library archive.
-linkall
Link all modules.

FILE EXTENSIONS

$ .ml   - Implementation
.mli  - Interface
.cmo  - Bytecode object
.cma  - Bytecode library
.cmi  - Compiled interface

EXAMPLE

$ # Compile simple program
ocamlc -o hello hello.ml

# With standard library
ocamlc -I +str str.cma program.ml -o program

INSTALL

sudo apt install ocaml
sudo dnf install ocaml
sudo pacman -S ocaml
sudo apk add ocaml5
sudo zypper install ocaml
brew install ocaml
nix profile install nixpkgs#ocaml

CAVEATS

Bytecode slower than native. Link order matters. Use ocamlopt for production.

HISTORY

OCaml was developed at INRIA (French computing research institute), evolving from Caml Light. The bytecode compiler has been part of OCaml since its creation.

SEE ALSO

ocamlopt(1), dune(1), opam(1)