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:
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.