Dependency problem when modules have the same name

Hi,

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:

dune

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

lib/m.ml

let answer = 42

m.ml

let () = print_endline "m"

test.ml

open Lib

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

Thanks!

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.

2 Likes

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…