dune "Library X not found" in the search path in CI
dune resolves libraries by name across the current project and the installed switch. When it cannot find one, the library is not installed, or the name in your stanza does not match a real library.
What this error means
dune build fails with "Error: Library \"X\" not found." or "Library X not found in the dune search path", naming the stanza that requested it.
File "bin/dune", line 3, characters 12-15:
3 | (libraries cmdliner))
^^^^^^^^
Error: Library "cmdliner" not found.Common causes
The library is not installed in the switch
The dependency was never installed with opam into the active switch, so dune finds no library of that name.
A wrong library name in the stanza
The (libraries ...) entry uses an import or package name that does not match the actual dune/findlib library name.
How to fix it
Install the library and rebuild
- Install the dependency into the active switch.
- Apply the switch env so dune sees it.
- Rebuild the project.
opam install cmdliner --yes
eval $(opam env)
dune buildUse the correct library name
Confirm the real library name and correct the stanza; sublibraries use a dotted name.
(libraries cmdliner lwt.unix)How to prevent it
- Install all project deps with
opam install . --deps-onlyfirst. - Match
(libraries ...)entries to real findlib names. - Apply the switch env before dune in each step.