Ocamlc fails for finding cmi with -I (-big i) option

compiler
build

#1

Hello,
I don’t know what I’m doing wrong, and could use some help regarding building…
I’m compiling a module which has an ml and mli files. If both such files are in the same directory everything works as expected (i.e after running some commands I get an a.out which “respects” what I wrote on the mli). If the I move the mli file to another directory and try to compile with -I option, the compiler doesn’t recognize the existance of the previously compiled cmi and overwrites it. Here some screenshots of the problem:

Is that normal?


#2

Maybe someone else can respond specifically about -I, but the folder structure you’re trying to use isn’t what most (all?) OCaml build tools expect, so you’re probably going to run into problems. I’d advise just keeping your .mli and .ml files in the same folder. It will make things a lot easier in the long term.

If you’re trying to expose a public interface separate from the private interface, the typical way is to have a module that just includes the modules and functions you want to make public, and then make that the only module you export (Dune calls this wrapped"libraries, although I don’t know how they do it).


#3

The compiler indeed expects to find the pair of .ml/.mli files in the same location, otherwise it considers that there is no .mli file and infer the corresponding interface for the provided implementation file by itself .

It might be interesting to be able to explictely associate an interface file with an implementation file.

Note also that include does not really reflect the functionality of mli files which describes an interface and are not really included anywhere.