Merlin complains about missing module in the same project

I'm new to Ocaml and just setting up my emacs, merlin and flycheck developers' environment. Everything works more or less as expected, except for one: merlin does not seem to be able to recognize dependencies between modules in the same project.

eg. I have a test project with two modules: main.ml and awesome.ml.

here is my main.ml that references the second awesome.ml module

(* main.ml *) open Core module A = Awesome let _ = Printf.printf "hello \n Converted to string we get: %s\n" (A.str_of_t (A.succ A.one_t)); 

here awesome.ml:

 (* awesome.ml *) type t = int let one_t = 1 let succ i = i + 1 let str_of_t = string_of_int 

when I send the main.ml buffer for calculation to utop using the utop-eval-buffer function, I get the error message: "Error: Unbound module Awesome"

I have .merlin at the root of a project that has an S instruction. I know that he was found by Merlin, since he does not complain about the "open core"

 S src PKG core lwt ounit B _build/src B +threads 

here is my _tags:

 <src/**>: include <src/**>: package(oUnit), package(core) true:thread 

regular compilation of the project with ocamlbuild works fine, no errors. here is the makefile

 ## Makefile default: main main: main.native test: test.native %.native: ocamlbuild -use-ocamlfind $@ mv $@ $* .PHONY: test default 

any ideas why the awesome module is not recognized in utop or is this the expected behavior?

+6
source share
3 answers

Merlin will see other modules after compiling them (in fact, as soon as you compile its interfaces). Therefore, if your .merlin correct, it will see everything after starting compilation. Your files should really be in the src folder, i.e. Your project layout based on your .merlin file should look like this:

 Makefile .merlin src/ awesome.ml main.ml 

This is not a required layout, but it is the one you described in Merlin. The reason why I suspect this is not the same is your Makefile .

PS As a note, there is a small problem in your code: you have to open Core.Std not Core .

+10
source

As Ivan pointed out the answer , Merlin can only recognize the module in your project after compiling it. If Merlin gives you an unbound module Foo error, one solution is to run

 ocamlbuild foo.cmi 
+1
source

I had the same problem. I tried installing merlin through opam or sources, but I could not solve this problem until I placed the ".merlin" file in the \ src directory - not in the root directory - with the "REC" tag.

+1
source

All Articles