Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
linking the same module more than once
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jake Donham <jake@d...>
Subject: linking the same module more than once

Consider the following code: let a () = raise (Unix.Unix_error (Unix.E2BIG, "", "")) try A.a () with Unix.Unix_error (_,_,_) -> ()

compiled with

  ocamlc -o test unix.cma unix.cma

Run it:

  > ./test
  Fatal error: exception Unix.Unix_error(0, "", "")

With exceptions raised from C code this can even happen within the same module: let a () = try Unix.mkdir "/tmp" 0o777 with Unix.Unix_error
(_,_,_) -> () A.a ()

There is no trouble linking a module more than once, but different
parts of the code can wind up linked to different instances of the
module, leading to the confusing behavior that exception handling
seems not to work (and generally that things you think are equal are
not). For exceptions raised from C code, since
Callback.register_exception is called twice, the C code has a
different instance from the ML code.

Ocamlopt catches multiple definitions; seems like ocamlc should also.
But I see bugs

suggesting that this is expected behavior. Is there some use for it?

(I ran into this trying to use the ocaml-ssl module, which for some
reason builds unix.cma into ssl.cma.)