Plasma GitLab Archive
Projects Blog Knowledge

Glue code

Imagine we have two packages p and q that are normally independent, i.e. one can link p without q, and q without p. However, when both p and q are used in the same program, it is expected that they cooperate with each other. Of course, this situation can be modeled with the help of subpackages (a real-world example of this are p=lablgtk and q=lablgl).

The idea is as follows: p has a subpackage p.for_q that contains code with special features for q, and q has a subpackage q.use_p that depends on p, p.for_q, and q, and that contains the code using the special features of p. Expressed in META files, p would define

# META file for p:
requires = "..."
archive = "..."

package "for_q" (
  requires = "p"
  archive = "..."
)
and q would define
# META file for q:
requires = "..."
archive = "..."

package "use_p" (
  requires = "q,p.for_q"
  archive = "..."
)
Of couse, the program using both libraries must explicitly enable the subpackages by mentioning "q.use_p" on the ocamlfind command line, otherwise the glue code would be omitted.

Unfortunately, it is not possible to use the package predicates pkg_p and pkg_q to add archives depending on whether the other package is also selected. The problem is that the order cannot be specified, i.e. whether p must be linked first or q.

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