In the same vein of using:
ocamlc -i foo.ml
to generate the default signature for foo.ml is there a way to generate signatures from compiled files (*.cmo) or archives (*.cma)?
My use case is that I have an archive abcd.cma I want to link with, containing numerous modules (say, modules a, b, c and d) and I don’t want to bother with the multiple *.mli and *.cmi my Makefile would need to handle to compile and link the user-side code (that uses the library). E.g. say I have file uses_a.ml that uses only the a module found in the abcd.cma archive. My understanding is that to link with the abcd.cma module I would have to go through the following motions:
ocamlc -i a.ml > a.mli
ocamlc -c a.mli
ocamlc -c uses_a.ml
ocamlc abcd.cma uses_a.cmo
Which seems too convoluted or impossible if I don’t have access to the sources or the signature. Given that I provide the entire archive to the compiler at the last command it is not clear to me why I have to go through the ritual of compiling (or generating – if I have access to the sources) the specific signature file for the module I am using. The last command could have been interpreted by the tool as an invitation to use the “default” signature of any module present in the archive that subsequent modules on the line use. BTW I don’t want to use automatic Makefile generation tools at this point.
If you have to compile a.ml and a.mli, there is no point having a library.
A library is normally composed of a
abcd.cmafile (or bothabcd.aandabcd.cmxain native code) and the set of interfaces (.cmi files) of the modules that are exported from the library. So, normally, in your case, the filea.cmishould be provided altogether with the library.In such a case, you just need to do: