Say, I have mylibrary.ml which provides wrappings to library.c and I want to bytecode-compile and provide mylibrary.ml as a library for other ocaml code. Compiling this to bytecode (and I am not considering compiling ocaml to native code here) produces a number of files, and I am wondering if there is any reason to keep them all? Or to provide them all to other users of the library?
I (so far) understand that I need the bytecode library object mylibrary.cma so that I can use mylibrary in the ocaml toplevel as
ocaml mylibrary.cma
or that I can
#load "mylibrary.cma";;
from an ocaml script. Then also the compiled interface mylibrary.cmi, and the dllmylibrary.so (which contains the C parts of the code) are needed for the above to work. And the non compiled interface definition file mylibrary.mli is nice to keep for documentation purposes.
But is there any reason to retain also the mylibrary.cmo file, if I have the mylibrary.cma file? In what kind of case would someone like to have that, too?
EDIT: I mean, I need to construct the .cmo in the makefile and then use that to construct the .cma, but I was thinking to remove .cmo after this, to keep the directory marginally cleaner.
So, apparently the purpose of different files are (when limiting this to bytecode compiler):
mylibrary.mli– human readable interface definition (not strictly needed, compiler only needs .cmi)mylibrary.cmi– compiled interface, needed when compiling code calling mylibrarylibrary.o– C object filedlllibrary.so– shared library object made of the.odlllibrary.a– static library object made of the.omylibrary.cmo– bytecode object compiled frommylibrary.mlmylibrary.cma– bytecode libraryThen,
mylibrary.cma(withmylibrary.cmianddlllibrary.so) are needed when loading mylibrary from the toplevel:#load "mylibrary.cma";;OR
One could compile a bytecode program that dynamically links with
mylibrary.cma(mylibrary.cmianddlllibrary.soalso needed):ocamlc mylibrary.cma <program>.mlOR
dynamically linking with bytecode object, instead of the bytecode library (files needed:
mylibrary.cmo,mylibrary.cmi,dlllibrary.so):ocamlc dlllibrary.so mylibrary.cmo <program>.ml(Note: then run the bytecode with:
ocamlrun -I . <program>, assumingdlllibrary.sois in the current directory.)OR
statically linking with objects (files needed:
mylibrary.cmo,mylibrary.cmiliblibrary.a)ocamlc -custom liblibrary.a mylibrary.cmo <program>.mlOR
statically linking with library objects (files needed:
mylibrary.cma,mylibrary.cmi,liblibrary.a)ocamlc -custom -I . mylibrary.cma <program>.mlSo depending on how one is going to use the library in the future, different files are needed. Except
.mliis only needed for human readers, and the object file.ocompiled from the C library is not needed (but would be needed when compiling to native code in some cases).