Dune and unbound module

Hello, here my project directory content (an example created for the topic).

test.ml
program.ml
dune-project
dune

The dune file.

(test
    (name test)
    (modules test)
    (libraries ounit2))

(executable
    (name program)
    (modules program))

test.ml

open Program 
open OUnit2

If I run the command “dune test” I got

File "test.ml", line 2, characters 5-11:
2 | open Program
         ^^^^^^
Error: Unbound module Program

Edit: the output was badly copy pasted in the post, many readers were probably unable to understand, sorry.

There’s no Program module among (modules test) and (libraries ounit2). Also the executable cannot be listed under libraries.

There’s two ways to approach this:

  1. Put Program into a dune library and make both the tests and the executable depend on that library.
  2. If you’ll only have these two modules, you can use the plural (executables) stanza and put both program and test into it. Then I think they can access each other. But you’ll need a separate (rule) to actually run test.exe then.
1 Like

“Program” is the main module, that sound wierd to make it a library.

I tried with a new file “main.ml”


(library
    (name program)
    (modules program))

(test
    (name test)
    (modules test)
    (libraries ounit2 program))

(executable
    (name main)
    (modules main)
    (libraries program))

Now it works but I added complexity to make dune working.