Dependency problem when modules have the same name


I ran into what looks like a bug to me: an executable depends on a library including a module with the same name as another executable that gets linked to the main program even if it’s not used at all. Is it the expected behavior?

Here’s a minimal example:


(executables (names test m) (libraries lib))


let answer = 42

let () = print_endline "m"

open Lib

let () =
  ignore M.answer;
  print_endline "test"


It is a known limitation of ocamldep: dependencies are only inferred locally, and this is situation making the hypothesis that the module M is the local one is the safer approximation.


OK, thanks! I guess I could duplicate the stanza and specify which modules are used for each executable.

Would it be possible for dune to inspect the compiler’s output to determine which object files to link? This approximation is okay when building object files, but becomes problematic as unexpected code (with side effects) gets executed…