Dynlink works in native mode but not in bytecode?

dynlink

#1

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)


#2

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


#3

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?


#4

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.