Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Module unavailable when compiling another file that uses it in OCaml

I have multiple compilation units in OCaml, one of which is causing a few problems. One compilation unit has two files foo_one.mli and foo_one.ml, these compile without any errors when using ocamlc. The other compilation unit has two files shoo.mli and shoo.ml. shoo.ml needs to make use of functions from foo_one, and so in the file shoo.ml I use open Foo_one. To compile, I use the command ocamlc foo_one.mli shoo.mli shoo.ml and the compiler returns the error: Module Foo_one is unavailable (required by Shoo).

What is causing this error and how can it be solved?

I made sure that the compilation units are all in the same directory, with the files in one compilation unit having the same name and capitalising the name of the module I am including in shoo.ml.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming you’ve compiled foo_one.mli and foo_one.ml with:

ocamlc -c foo_one.mli foo_one.ml

Then you should be compiling shoo.ml with:

ocamlc foo_one.cmo shoo.mli shoo.ml

If you had provided the -c option, you could compile with the following because you’re not yet linking the two, and thus Shoo only needs to know the interface Foo_one exposes.

ocamlc -c foo_one.mli shoo.mli shoo.ml

If you did this, you could finally link the two together to create an executable with:

ocamlc foo_one.cmo shoo.cmo
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading