Objective Caml provides a platform-independent bytecode format for executables. The same application runs on different operating systems, on different CPUs (even on CPUs with different endianess). This is comparable to Java, but note that there are some fundamental differences:
Note that O'Caml also has, unlike Java, a high-performance native code compiler that produces machine code. On this web site, however, I will not provide any platform-specific compiled applications; you must download the sources and compile the applications yourself if you want maximum performance.
[Important note:The O'Caml Runtime Environment (ocamlre) has only been made for the version 3.01 of the compiler. There will be no ocamlre for the version 3.02. Once 3.03 is out, I will again extract the runtime engine from the full distribution, but it will be unpatched because this version of the compiler will already support dynamic loading. The following explanations only apply to version 3.01.]
The bytecode interpreters coming with the O'Caml source distribution are always statically linked with a fixed set of libraries, and they can only run binaries that need exactly the same set. As this is a bit inconvenient, I have extracted the runtime system from the O'Caml sources, and added a more flexible scheme to cope with the differing sets of libraries. This modified runtime system is called "O'Caml Runtime Environment", and can be downloaded from this directory as source archive, and as already compiled binary for several operating systems.
Once the runtime system is installed, there is a new program ocamlre that can start bytecode executables using a variety of libraries. You can find out what is possible by just starting ocamlre without arguments. On my Linux machine, I get the following output:
Objective Caml Runtime Environment - O'Caml version: 3.01 - File format for bytecode executables: Caml1999X006 - Directory with runtime libraries: /opt/ocaml-3.01/ocamlre// - Available libraries: libcamlrun libunix libstr libnums libbigarray libthreads libgraphics libmldbm liblabltk41The interpreter can execute all bytecode files using some or even all of the listed libraries.
To start a bytecode file, call the interpreter by
ocamlre bytecodefile arg1 arg2 ...This command will examine the specified bytecode file and will find out which libraries are needed. A customized interpreter will be built "on the fly" by loading the libraries dynamically (on some platforms, however, this is not possible because the dynamic loader of the operating system is too restrictive concerning shared global variables; in this case a pre-built interpreter will be executed).
Alternatively, you can prepend a "#!" line to the bytecode file. For example, if ocamlre is installed in /usr/local/bin, just put the line
#! /usr/local/bin/ocamlre-3.01at the beginning of the bytecode file. (Note that there is always an ocamlre-<version> such that you can refer to the version of the runtime system that works for your bytecode file.)