I have this interface for plugins to register plugins in my program:
let ht : (string, (string * (_ -> _ -> bool))) Hashtbl.t = Hashtbl.create 0 let assets = ref "" let register ~ns m fn = let fn = fn !assets in Hashtbl.add ht m (ns, fn) let get = Hashtbl.find_opt ht
Then I have the main executable loading plugins this way:
let register_plugin dir = let assets = Filename.concat dir "assets" in GwdPlugin.assets := assets ; Secure.add_lang_path assets ; Dynlink.loadfile (Filename.concat dir "plugin.cmxs") ; GwdPlugin.assets := ""
But I have a lot of problems when trying to use libraries which are not included in my main program.
I tried to use
-linkall. Each time I get un undefined symbol, I add the corresponding lib in
(executable (name plugin) (libraries aaa) (embed_in_plugin_libraries bbb ccc ddd) (flags -linkall) (modes (native plugin)) )
aaa si the library of my main program (plugin registration + the rest of its world),
bbb ccc ddd libraries not used in the main program.
But now, I am stuck because the undefined symbol is actually
undefined symbol: camlStdlib__lexing__engine_113
- Is it possible for my main program to link the whole stdlib without the compiler removing ? It is ok for me to state that the main program to embed unused code if it is only the stdlib (maybe this would be sufficent to solve the issue)
- Is it possible for my plugin to embed stdlib as I did it with other libs ? Can’t find a package for this.
- Am I just doing it wrong?