Plasma GitLab Archive
Projects Blog Knowledge

Programming with Objective Caml Document Tree [News][Projects][Links][Tree]

Download bytecode
 Download other


Download Caml bytecode executables

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:

  • The format of the bytecode executables changes frequently, such that you can only execute an O'Caml 3.01 binary with an O'Caml 3.01 interpreter. The versions must match exactly.

  • The O'Caml bytecode files are self-contained, i.e. they need not to be linked to a standard bytecode library at runtime (i.e. no ""). The bytecode files are larger, but start very quickly.

  • There is no "sandbox" in O'Caml. Bytecode executables have access to all means of the operating system.

  • The bytecode interpreter is extensible. You can add new primitives by writing a C library and linking that library to the interpreter. On the one hand, this has the advantage of more flexibility, on the other hand, this means that the interpreters differ in functionality. Interpreter X may include a library that is missing in interpreter Y.

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.

The O'Caml Runtime Environment

[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:
The 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.01
at 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.)

The bytecode executables

  • Hello world: Four bytecode files:

    • helloworld: needs only the core interpreter libcamlrun

    • strtest: needs libstr

    • graphtest: needs libgraphics

    • labltktest: needs liblabltk41

    tarball for ocamlre-3.01

    (The sources are included in the ocamlre source tarball, and trivial.)

  • pxpvalidate: This is the XML validator PXP as stand-alone command. Just type

    pxpvalidate file.xml
    to validate the specified file. Tarball for ocamlre-3.01 (Includes an installation script). The sources are contained in the PXP tarball.
  • pxpvalidate: There is another bytecode executable that works for O'Caml 3.03-alpha. Because there is no runtime-only distribution you must install the full O'Caml 3.03-alpha environment.

This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml