Plasma GitLab Archive
Projects Blog Knowledge

How a package directory looks like

Let us assume that the package p implements the modules M1 and M2. If you compile m1.mli and m2.mli you get the corresponding binary files m1.cmi and m2.cmi describing the interfaces of the modules. Of course, these cmi files must go into the package directory. It is recommended to put the source mli files into the directory, too, as they document the interface.

Another product of the compilation are two cmo files, m1.cmo and m2.cmo (we assume the bytecode compiler, the native compiler would create m1.cmx and m2.cmx). It is possible to put these files directly into the directory, but there is a better way. As it makes only sense to use both modules (a very common assumption), they should first be archived by doing

ocamlc -a -o p.cma m1.cmo m2.cmo

The archive p.cma contains both cmo files, and preserves the order of the files. Assumed that in M2 there is a reference to an entity in M1, M2 depends on M1 and when linking a program using these modules, M1 must be mentioned first (e.g. ocamlc m1.cmo m2.cmo program.ml)[1]. If you create the archive p.cma it contains already this dependency, and you need not to remember it when linking in the p.cma.

So far the files m1.cmi, m2.cmi, and p.cma are needed, and m1.mli and m2.mli are recommended. Usually there is another file in the directory, META, containing additional information about the package. In our example, META looks like

description = "Our super-duper package"
requires = ""
version = "1"
archive(byte) = "p.cma"

The variable "requires" contains a list of packages that are required by this package (the names may be separated by commas or spaces). As our package, p, does not depend on any other package, this list is empty. I'll explain what happens with non-empty lists below.

The variable "version" is simply a version string, and "description" is a short comment on the package.

The variable "archive" denotes the files that have to be actually linked in if the package is used. This is again a list of (file) names. In contrast to the other variables, "archive" has a condition, written in parantheses. This value of "archive" will only be used if the predicate "byte" is true; this predicate is usually given if the program is compiled to bytecode. If you have a native archive, p.cmxa, of the two modules M1 and M2, you can add another line to META:

archive(native) = "p.cmxa"

The correct value for the "archive" variable is selected upon the given set of predicates.

Notes

[1]

Note that C linkers usually require the reverse order, but only for archive elements, i.e. files with suffix .a.

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