Ocamlfind, trying to understand which files to install

When I ocamlfind install some files, I am always a bit unsure which files I should install.

For example, I believe that the .cmxa file should already contain the associated cmx files. So I try to avoid installing the cmx. But then subsequent compilation (eg when building a native executable that uses the library) fails to find a .cmx file. If I install the .cmxa and all the .cmx, everything is fine. But then, doesn’t the cmxa include the cmx? Why do I need the cmxa and the cmx?

I don’t have an answer but there is this comment in the compiler source:

There is no need to keep the approximation in the .cmxa file,
since the compiler will go looking directly for .cmx files.
The linker, which is the only one that reads .cmxa files, does not
need the approximation.

So it seems the compiler will during compilation of a module look for .cmx files of the dependencies and only during a later linking step the linker will consult the .cmxa.

Truth be told, I would not go around and installing things manually — personally I really don’t enjoy working with projects that decided to do a reinvention of a build system which then ends up missing things or installing things in odd places. I would recommend you to use an existing system which will compile code with sensible flags and also install all required files in the right locations.

Yes. Invoking ocamlfind directly used to be the norm a few years ago, but today this is a smell. I’d recommend using dune if possible, or if you’re using ocamlbuild, you can use topkg to manage the installation part.

1 Like