Note that even though it wasn’t properly designed for that, the omod
command line tool that comes up with omod
(a toplevel helper to load what you want by module name rather than by library name which I find more natural) can help answering these questions – though it reports them at a lower level. For example:
> omod cobj Misc
Misc 9d0e49da1703d17dc3043e52bca13fe5 /Users/dbuenzli/.opam/4.14.0/lib/ocaml/compiler-libs/misc.cmi
Misc 9d0e49da1703d17dc3043e52bca13fe5 /Users/dbuenzli/.opam/4.14.0/lib/ocaml/compiler-libs/misc.cmx
Misc 9d0e49da1703d17dc3043e52bca13fe5 /Users/dbuenzli/.opam/4.14.0/lib/ocaml/compiler-libs/ocamlcommon.cma
Misc 9d0e49da1703d17dc3043e52bca13fe5 /Users/dbuenzli/.opam/4.14.0/lib/ocaml/compiler-libs/ocamlcommon.cmxa
Since nowadays a library foo
defined in an opam pkg
is most of the time installed as $(opam var lib)/pkg/foo/foo.cm[x]a
you should be able to infer the library name and opam package of a given module name (more precisely of a given compilation unit name)
But, as the example above shows, that’s not always the case.