Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: -- (:)
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: 
-, dynamically loading the plugin
-, the loaded code that depends on the external lib
-, the external lib

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

compiled with ocamlopt -o MyProg dynlink.cmxa

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

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

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

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