# Dune: depending on local module "Library not found"

**URL:** <https://discuss.ocaml.org/t/dune-depending-on-local-module-library-not-found/5793>\
**Category:** Learning\
**Tags:** dune\
**Created:** [May 17, 2020, 9:53pm UTC](https://discuss.ocaml.org/t/dune-depending-on-local-module-library-not-found/5793 "2020-05-17T21:53:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![evanm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/evanm/32/2222_2.png) [@evanm](https://discuss.ocaml.org/u/evanm)\
**Post date:** [May 17, 2020, 9:53pm UTC](https://discuss.ocaml.org/t/dune-depending-on-local-module-library-not-found/5793/1 "2020-05-17T21:53:37Z")

</div>

Under my project root I have two folders, one for library code and one for the final binary built from main.ml. Unfortunately I’m missing something since dune can’t seem to find the library code

```
File "bin/dune", line 3, characters 12-15:
3 | (libraries lib))
                ^^^
Error: Library "lib" not found.
Hint: try: dune external-lib-deps --missing @@default

```

Here’s the folder structure:

```auto
.
|-- bin
| |-- dune
| |-- dune-project
| `-- main.ml
|-- dune-project
`-- lib
    |-- dune
    `-- math.ml

```

Here’s bin/dune:

```auto
(executable
 (name main)
 (libraries lib))

```

And lib/dune

```auto
(library
 (name lib))

```

From the dune [documentation](https://dune.readthedocs.io/en/stable/concepts.html#library-deps) on library dependencies it seems like dune should automatically find libraries defined within the current scope / workspace. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![evanm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/evanm/32/2222_2.png) [@evanm](https://discuss.ocaml.org/u/evanm)\
**Post date:** [May 18, 2020, 12:47am UTC](https://discuss.ocaml.org/t/dune-depending-on-local-module-library-not-found/5793/2 "2020-05-18T00:47:35Z")

</div>

I ended up getting this to work after investigating a bit further, although I’m still not exactly sure why it works now.

I modified main.ml and added `open Lib`, after which dune built everything without complaint. I thought perhaps dune throws an error to prevent unused dependencies from being included, but I’ve also listed base as a dependency in the dune file, without opening it in `main.ml`, and dune is fine with that.

If anyone knows why I’m observing this behavior, I’d be curious to know.

---

<div class="post-metadata">

**Author:** ![Leonidas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/leonidas/32/4039_2.png) [@Leonidas](https://discuss.ocaml.org/u/Leonidas)\
**Post date:** [May 18, 2020, 2:03pm UTC](https://discuss.ocaml.org/t/dune-depending-on-local-module-library-not-found/5793/3 "2020-05-18T14:03:17Z")

</div>

Do you have a git repo where we could test that without having to reproduce it ourselves? You should not be required to use `open Lib`, a practice that I find pretty bad for readability of code in any case.

---

<div class="post-metadata">

**Author:** ![evanm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/evanm/32/2222_2.png) [@evanm](https://discuss.ocaml.org/u/evanm)\
**Post date:** [May 18, 2020, 4:53pm UTC](https://discuss.ocaml.org/t/dune-depending-on-local-module-library-not-found/5793/4 "2020-05-18T16:53:17Z")

</div>

Unfortunately when I tried this again today I couldn’t reproduce the error. However, as I wrote that last sentence I realized the difference between the code now and before is that previously I had a stray `dune-project` file in the bin directory.

If you clone the sample repository I created and copy the `dune-project` file into the bin directory you can reproduce the error. To your point about not needing to `open Lib` - you’re right. I tested things out today and it works properly without opening the library.

> **[emesterhazy/dune\_test](https://github.com/emesterhazy/dune_test)**
>
> Contribute to emesterhazy/dune\_test development by creating an account on GitHub.

Thanks!

---

<div class="post-metadata">

**Author:** ![Leonidas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/leonidas/32/4039_2.png) [@Leonidas](https://discuss.ocaml.org/u/Leonidas)\
**Post date:** [May 19, 2020, 12:43pm UTC](https://discuss.ocaml.org/t/dune-depending-on-local-module-library-not-found/5793/5 "2020-05-19T12:43:59Z")

</div>

Yes, so `dune-project` acts as “anchor” to determine where the project root is, and if it finds it in a folder from where there is no subfolder with a `lib` library this is exactly what happens.

I am glad we could figure out the reason for this weird behaviour you were seeing!

---

<div class="post-metadata">

**Author:** ![Luc\_ML](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/luc_ml/32/1671_2.png) [@Luc\_ML](https://discuss.ocaml.org/u/Luc_ML)\
**Post date:** [May 20, 2020, 2:38am UTC](https://discuss.ocaml.org/t/dune-depending-on-local-module-library-not-found/5793/6 "2020-05-20T02:38:27Z")

</div>

> [@Leonidas](#):
>
> Yes, so `dune-project` acts as “anchor” to determine where the project root is, and if it finds it in a folder from where there is no subfolder with a `lib` library this is exactly what happens.

Yes, and dune doesn’t tell you what it does.  
@evanm: you may reproduce something like your problem if your try to build one of the example that are still within dune source 2.5.1, say [dune/example/sample-projects/hello\_world at 2.5.1 · ocaml/dune · GitHub](https://github.com/ocaml/dune/tree/2.5.1/example/sample-projects/hello_world) .

Doing `dune build` does nothing (with no message, which is puzzling and disappointing).  
Doing `dune build --root .` (dot for current directory) from within the hello\_world directory works (you have to dig in \_build/default because nothing is visible).  
You should also think about doing `dune runtest --root .` and `dune clean --root .` to make something happen.

What happens if you try `--root .` your files tree?  
Also, try `--verbose` to gain visibility and let us know.
