Plasma GitLab Archive
Projects Blog Knowledge

Does findlib support linking of applications as well as packages?

Short answer: Yes, but it is not very obvious

Applications also depend on other components, they have predicates, sometimes they need linker options; there seems to be only little difference between applications (stand-alone programs) and packages. If you want to use the findlib mechanisms for applications, too, the following trick helps.

The environment variable OCAMLPATH may contain a colon-separated path of possible sitelib locations. It is allowed to include "." into the path (Shell commands follow):

OCAMLPATH=.
export OCAMLPATH
This makes ".", i.e. your current directory, another sitelib location. You may now put the components of your applications into subdirectories together with META files; the hierarchy might look as follows:
./Makefile                          global Makefile
./localpkg1/META                    first local package directory: Contains META
./localpkg1/...                     ... and more
./localpkg2/META                    second local package dir: Contains META
./localpkg2/...                     ... and more
...
From findlib's point of view, these directories are now package directories, and you can refer to them on the command line:
ocamlfind ocamlc -o ... -linkpkg -package localpkg1,localpkg2,...
If you do not want subdirectories, you can also refer to the META file in the same directory by the name ".", e.g.:
ocamlfind ocamlc -o ... -linkpkg -package .
In this case, the linking information will be taken from ./META.
This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml