linkerdependenciesocamldune

Including subpackages using dune (no implementation provided for modules, but modules are in dune file)


While compiling a project with dune that uses the fmt and logs packages , I ended up getting this weird error

File "_none_", line 1:              
Error: No implementations provided for the following modules:
         Fmt_cli referenced from bin/.main.eobjs/native/dune__exe__Main.cmx
         Logs_fmt referenced from bin/.main.eobjs/native/dune__exe__Main.cmx
         Fmt_tty referenced from bin/.main.eobjs/native/dune__exe__Main.cmx
         Logs_cli referenced from bin/.main.eobjs/native/dune__exe__Main.cmx

This clearly indicates that the linker is missing the object file containing those modules.

Problem, I checked, those libraries are installed with opam in the current switch, and my dune file contains

 (libraries ... fmt logs))


Solution

  • After searching a bit, I realized those modules are contained in separate object files in the opam switch

    _opam/lib/fmt/fmt_cli.cmx
    _opam/lib/fmt/fmt_tty.cmx
    _opam/lib/logs/logs_fmt.cmx
    _opam/lib/logs/logs_cli.cmx
    

    Those are part of opam subpackages (each defined in the META file in the same directory)

    I needed to add them individually to the dependencies with the following

     (libraries ... fmt logs fmt.cli fmt.tty logs.fmt logs.cli))