Skip to content
Latchkey

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.

dune
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

  1. Install the dependency into the active switch.
  2. Apply the switch env so dune sees it.
  3. Rebuild the project.
Terminal
opam install cmdliner --yes
eval $(opam env)
dune build

Use the correct library name

Confirm the real library name and correct the stanza; sublibraries use a dotted name.

bin/dune
(libraries cmdliner lwt.unix)

How to prevent it

  • Install all project deps with opam install . --deps-only first.
  • Match (libraries ...) entries to real findlib names.
  • Apply the switch env before dune in each step.

Frequently asked questions

What causes ""Library X not found""?
The dependency was never installed with opam into the active switch, so dune finds no library of that name.
How do I fix "Library X not found"?
Install the library and rebuild

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card