Unbound module and module type in dune build

Hi. Wanted to try out dune today with a basic project, but couldn’t get it working. Here is my project structure

test/
├── dune-project
├── test.opam
├── lib/
│   ├── dune
│   ├── greeter.ml
│   └── greeter.mli
├── bin/
│   ├── dune
│   └── main.ml

while doing dune build I got 2 errors.

 test  ᐅ  dune build            
File "lib/greeter.ml", line 1, characters 17-28:
Error: Unbound module type Greeter_sig
File "bin/main.ml", line 2, characters 2-15:
Error: Unbound module Greeter

Files in the lib folder

greeter.ml

module Greeter : Greeter_sig = struct
  let greet name =
    Printf.printf "Hello, %s!\n" name
end

greeter.mli

module type Greeter_sig = sig
  val greet : string -> unit
end

dune (the one in the lib directory)

(library
 (name test)
 (public_name test)
 (modules greeter) )

Now dune-project

(lang dune 2.8)

(name test)

and finally bin directory

main.ml

let () =
  Greeter.greet "World"

dune

(executable
 (name main)
 (libraries test))

Any ideas on how to fix it?

OCaml source files are automatically modules, so you don’t need to declare nested modules with the module and module type keywords. Also, I strongly recommend that you match each directory’s name with the name of its main module. This will greatly reduce the number of different concepts you have to worry about:

bin/
  bin.ml
  dune
greeter/
  dune
  greeter.ml
  greeter.mli

And the dune files:

; bin/dune
(executable
  (name bin)
  (libraries greeter))

; greeter/dune
(library
  (name greeter))
1 Like