I cannot get ocamlbuild to link properly under a very specific situation that involves nested and packed modules. The following is a minimal example that reproduces the problem.

$ cat a2.mli
val f : unit -> unit

$ cat a2.ml
let f _ = ()

$ cat lib.ml 
module A = A2

$ cat b.ml
let g = Lib.A.f

$ cat sup.mlpack 
B

$ cat prog.ml 
let _ = Sup.B.g ()

Now try compiling:
$ ocamlbuild prog.byte
+ /Users/ashish/godi/bin/ocamlc.opt lib.cmo sup.cmo prog.cmo -o prog.byte
Error while linking lib.cmo: Reference to undefined global `A2'
Command exited with code 2.

The problem is that a2.cmo should be included but is not. The linking is done correctly if I do any of the following:
- delete a2.mli
- in prog.ml, directly call Lib.A.f (which is what Sup.B.g is defined as)
- in prog.ml, directly call B.g, without packing B in Sup

I would appreciate any help. Thank you.