English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Dynamic loading of native code : what about librairies and packs ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-09-01 (08:55)
From: Pierre-Loïc Garoche <Pierre-Loic.Garoche@o...>
Subject: Re: [Caml-list] Dynamic loading of native code : what about librairies and packs ?
Hi Alain, Julien and all other Ocaml list members,

I am still having some problems with the dynamic loading of native code. Allow me to give you an extremely simple example to illustrate my problem. I hope you can clarify my understanding of it.

My problem concerns the dynamic loading of native code where the dynamic code loaded depends on another library.

Basically there are three files: 
- main.ml, dynamically loading the plugin
- plugin.ml, the loaded code that depends on the external lib
- mylib.ml, the external lib

let _ = print_string "main\n"
let _ = Dynlink.loadfile "MyPlugin.cmxs"

compiled with ocamlopt -o MyProg dynlink.cmxa main.ml

let _ = print_string "mylib\n"
let myval : (int , int) Hashtbl.t = Hashtbl.create 13

compiled with ocamlopt -a -linkall -o mylib.cmxa mylib.ml

let _ = print_string "plugin\n"
let cst = Mylib.myval

compiled and linked to build a shared library with
ocamlopt -shared -linkall -o MyPlugin.cmxs mylib.cmxa plugin.ml

Running it gives me the following error
error loading shared library: blabla/MyPlugin.cmxs: undefined symbol: camlHashtbl__create_79

Remark1 : Of course, building a standalone plugin works:
ocamlopt -o PluginSelf mylib.cmxa plugin.cmx

Remark2: If I don't rely on an external module and replace myval by an integer or any other self defined type value, it works as well.

Remark3: The linkall option does not seems to have an impact on such simple example.

Question: How should I link it to rely on external libraries and produce a valid MyPlugin.cmxs ?

Any hint or comment will be greatly appreciated !

Best regards,


Pierre-Loïc Garoche