Dynlink works in native mode but not in bytecode?



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:


They contain:
base.ml: general library code used throughout.
m_setup.ml: common parameter settings for all runs

open Base
include M_setup
(*...specific parameter settings for run <i>*)


open Base
let subdir = Sys.argv.(1)
      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)


Did you make sure to link M_setup into run ? You may need to pass -linkall to make sure it is linked in.


hmm. i tried adding the tag linkall for all files to ocamlbuild’s _tags file by including the line
<**/*>: linkall.
this did not help. also, why would it work for native compilation without linkall?


Hard to say without taking a look at the details; you may have more luck if you can come up with a smaller reproduction and possibly the explicit commands you are using to build your plugins and the main program.