Standalone Executables
A standalone executable is a program that does not depend an Objective CAML installation to run. This facilitates the distribution of binary applications and robustness against runtime library changes across
Objective CAML versions.
The Objective CAML native compiler produces standalone executables by default. But
without the -custom option, the bytecode compiler produces an
executable which requires the bytecode interpreter ocamlrun. Imagine the file example.ml is as follows:
let f x = x + 1;;
print_int (f 18);;
print_newline();;
Then the following command produces the (approximately 8k) file example.exe:
ocamlc -o example.exe example.ml
This file can be executed by the Objective CAML bytecode interpreter:
$ ocamlrun example.exe
19
The interpreter executes the Zinc machine instructions contained in the file example.exe.
Under Unix, the first line of the file example.exe contains the location of the interpreter, for example:
#!/usr/local/bin/ocamlrun
This means the file can be executed directly (without using ocamlrun. Like
a shell-script, executing the file in turn runs the program specified on the first
line, which is then used to interpret the remainder of the file. If ocamlrun can't be found, execution will fail and the error message Command not found will be displayed.
The same compilation with the option -custom produces a standalone executable with name exauto.exe:
ocamlc -custom -o exauto.exe example.ml
This time the file is about 85K, as it contains the Zinc interpreter as well as the program bytecode.
This file can be executed directly or copied to another machine (using the same
CPU/Operating System) for execution.