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

Unbound Module (Personal Files)

I have two .ml files, type.ml and main.ml, in the same directory.

I am following this official link: https://ocaml.org/docs/modules

File main.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

open Type

let () = print_endline "Hello World!"

I compile with this line, accordingly to the tutorial:

ocamlopt -o main main.ml type.ml

However, I have this error:

Error: Unbound module Type

>Solution :

The source files need to be ordered with the dependencies coming before the dependent. That is, it should be:

ocamlopt -o main type.ml main.ml

This is somewhat vaguely explained in the manual:

The order in which .cmx and .ml arguments are presented on the command line is relevant: compilation units are initialized in that order at run-time, and it is a link-time error to use a component of a unit before having initialized it. Hence, a given x.cmx file must come before all .cmx files that refer to the unit x.

Also, if you’re doing anything more significant I would recommend using a build system like dune to avoid having to mess with details like this.

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