LinuxCommandLibrary

ocamlopt

OCaml native-code compiler

TLDR

Compile to native code

$ ocamlopt -o [program] [source.ml]
copy
Compile multiple files
$ ocamlopt -o [program] [file1.ml] [file2.ml]
copy
Compile with optimization
$ ocamlopt -O3 -o [program] [source.ml]
copy
Compile to object file
$ ocamlopt -c [source.ml]
copy
Create native library
$ ocamlopt -a -o [library.cmxa] [file1.ml] [file2.ml]
copy

SYNOPSIS

ocamlopt [options] files...

DESCRIPTION

ocamlopt is the OCaml native-code compiler. It produces fast executables by compiling OCaml to native machine code instead of bytecode.
Native code runs significantly faster than bytecode but isn't portable across architectures.

PARAMETERS

-o file

Output filename.
-c
Compile only.
-O level
Optimization level (0-3).
-I dir
Include directory.
-g
Debug info.
-a
Create library.
-inline n
Inline threshold.

FILE EXTENSIONS

$ .ml   - Implementation
.mli  - Interface
.cmx  - Native object
.cmxa - Native library
.o    - Object file
copy

COMPARISON

$ ocamlc   - Bytecode, portable, slower
ocamlopt - Native, fast, arch-specific
copy

CAVEATS

Compilation slower than bytecode. Platform-specific output. Debugging harder than bytecode.

HISTORY

The OCaml native compiler was developed at INRIA to provide high-performance compilation while maintaining OCaml's type safety.

SEE ALSO

ocamlc(1), dune(1), opam(1), ocamldebug(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community