Connection between libraries in Opam, Dune, and Findlib

Hi,

In dune files, everything that is in (libraries ...) refers to findlib names. That is the same as what as in package(...) in _tags with ocamlbuild.

This does not always involve findlib: within a project, dune will be able to resolve libraries by itself, for example when linking your test suite against your lib.

Strictly speaking, the library names (for findlib) and opam package names are not related. For packages using topkg or calling ocamlfind install directly, it is up to the package author to specify the exposed modules, the library name, and the package name.

Base libraries in particular do not use strictly the same name. That is also the case in some common libraries: for example the ounit package exposes a oUnit library which has a OUnit2 module.

dune is a bit less flexible: the library name is always the same as the package name. That is derived from the (public_name).

opam used to have some support for exposing the mapping between libraries and packages: findlib files. It seems that it does not exist anymore though.

To avoid the confusion, the best practice these days is to make packages expose a single library, which exposes a single module, all named the same (that’s what you get when using dune with the default (wrapped true) mode).

3 Likes