Using modules of lib from bin (project created by dune init project)

I have created a project with dune init project project_name.

I have put in its lib directory the content of a package I would like to debug. Then, I have inside it a letters.ml and letters.mli. The dune file has been changed to match my project name.

But when I try to compile the whole thing (dune build), I have the following error despites the presence of letters.mli:

File "bin/main.ml", line 5, characters 15-34:
5 |   let config = Letters.Config.make ~username:"" ~password:""
                   ^^^^^^^^^^^^^^^^^^^
Error: Unbound module Letters

What should I do to make the module of the lib directory visible from bin/main.exe

1 Like

I think I’m probably about two days ahead of you in my dune learning, so this might have typos.

Assuming you are planning to have multiple modules in that lib/ directory at some point you want something like this in your lib/dune:

(library
  (name mylib)
  (libraries <any libraries you rely in in these modules>)
)

In your bin/dune:

(executable
  ...
  (libraries mylib)
)

And in your main file you can either refer to Mylib.Letters or do module Letters = Mylib.Letters.

If you want to generate docs with odoc you probably want to set public_name for the library too.
There are a bunch of different naming rules that interact here I think, with the filename=modulename thing plus dune’s stanzas.

1 Like

that’s exactly how I do it in all my projects, e.g. Weiterleitung