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
From the dune documentation on library dependencies it seems like dune should automatically find libraries defined within the current scope / workspace. What am I doing wrong?
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.
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.
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.
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!
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.