LinuxCommandLibrary

ocamlc

OCaml bytecode compiler

TLDR

Compile to bytecode

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

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
copy

EXAMPLE

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

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

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), ocamldep(1), dune(1), opam(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community