I have the peculiar situation that i can successfully compile and run the native code version of my dynlinked code but not the bytecode version. Who has an idea what I am doing wrong?!
I am using the following setup to dynamically load a module M_dyn
:
The relevant source files:
base.ml
m_setup.ml
run.ml
run1/m_dyn.ml
run2/m_dyn.ml
...
They contain:
base.ml
: general library code used throughout.
m_setup.ml
: common parameter settings for all runs
run<i>/m_dyn.ml
:
open Base
include M_setup
(*...specific parameter settings for run <i>*)
run.ml
:
open Base
let subdir = Sys.argv.(1)
Dynlink.(
loadfile (Filename.concat subdir (adapt_filename "m_dyn.cmo")))
(* now run stuff with the loaded parameter settings *)
I am using ocamlbuild for building (no time for conversion to dune right now).
I can successfully build run1/m_dyn.cmxs
and run.native
and then run ./run.native run1
.
I can also build run1/m_dyn.cmo
and run.byte
, but on running ./run.byte run1
i get the error:
Dynlink error: error while linking _build/run1/m_dyn.cmo.
Reference to undefined global `M_setup'
(edit: this is a simplified version of my actual example, with what i hope are the relevant bits. both m_dyn and run are compiled against the same interface, which is why the native version does work fine - i did not explicitly list that interface file. for the sake of the example, let’s say the interface is included in base.ml
)