Certain modules that ship with OCaml like Unix
and Bigarray
have their own .cmx
and .cmxa
files in ocamlopt -where
(which is ~/.opam/4.03.0/lib/ocaml
on my system in my current opam switch).
Is there a way to determine without compiling which source files depend on which of these "special" libraries in the standard distribution? I'm intending to consume this output later in a Makefile.
The following program example.ml
open Unix;;
Unix.system "echo hi";;
Can be compiled using ocamlfind ocamlopt -package unix -linkpkg example.ml
. I'm not sure how to compile it without going through the ocamlfind
wrapper.
I'm wondering if there's a way to statically detect that the unbound-in-this-file module Unix
corresponds to "something" in the standard distribution and report unix.cmxa
as a dependency. ocamldep
does not seem to report it as a dependency by default.
ocamldep -all example.ml
just reports that the various object and interfaces files that can be produced using example.ml
depend on example.ml
. I was hoping for either an error message complaining that ocamldep doesn't understand the Unix
module or some indication that it's required to build the objects.
$ ocamldep -all example.ml
example.cmo example.cmi : example.ml
example.cmx example.o example.cmi : example.ml
I understand that your question is:
For a given module name, say
Unix
, how can we find the library which provides it?
Unfortunately there is no such a tool (yet).
If we limit the search space to the libraries come with the OCaml compiler itself, I would do:
$ ocamlobjinfo $HOME/.opam/4.03.0/lib/ocaml/*.cma | grep '^\(File\|Unit name\)'
This will list all the modules defined in each archive. You may or may not find the module name in the result.
It is impossible in general, since the library you seek may not be standard or may not be installed locally. You can use API search engines like ocamloscope but they never cover all the OCaml libraries ever written of course.