Original bug ID: 4166 Reporter:@mmottl Status: resolved (set by @xavierleroy on 2015-11-22T10:45:03Z) Resolution: open Priority: normal Severity: minor Version: 3.09.3 Target version: 4.03.0+dev / +beta1 Fixed in version: 4.03.0+dev / +beta1 Category: ~DO NOT USE (was: OCaml general) Has duplicate:#6956 Related to:#4374#6063 Monitored by: yziquel mehdi @ygrek@hcarty@dbuenzli@Chris00@mmottl
We have a module (lets call it "Foo") that interfaces C-bindings and exports functions defined as "external" in its .mli-file. This module is packed with others into one module, which again is part of a .cmxa-file.
If we link this library with another module (say, "Bar") that uses only functions defined "external" in "Foo", we observed that toplevel expressions in "Foo" did not get evaluated.
Here is a schematic example:
external foo : unit -> unit = "foo"
external init : unit -> unit = "init"
let () =
external foo : unit -> unit
let () =
Since "Bar" depends on "Foo", you would expect that the toplevel expression in "foo.ml" gets evaluated first, which should print "init" and e.g. initialise the C-bindings. But we see "bar" first, and our application crashes, because the C-bindings are not evaluated.
Interestingly, changing "foo.mli" as follows solves the problem:
val foo : unit -> unit
This indicates that exclusively calling functions exported as "external" will prevent the linker from figuring out which modules should be initialized first. This seems to be a bug, it shouldn't matter whether we use "val" or "external".
The text was updated successfully, but these errors were encountered: