Version française
Home     About     Download     Resources     Contact us    
Browse thread
Tutorial example for nat dynlink
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Yves Bertot <Yves.Bertot@s...>
Subject: Tutorial example for nat dynlink
Hello,

I have been trying to build a small example "hello world" program using 
native dynlink, but
I don't manage to make it work.  Could please send me some advice?


Here are my programs:

-------- toto.mli ----
val ff : (unit -> unit) ref;;
-------- toto.ml -----
Dynlink.init();;

let ff = ref (fun () -> ());;

try Dynlink.loadfile "bidon.cmxs" with Dynlink.Error(e) ->
  print_string (Dynlink.error_message e ^ "\n");;

!ff();;
------ bidon.ml -----
let hello () = print_string "hello world!\n";;

Toto.ff := hello;;
------ end of files ------

ocamlopt -v returns

The Objective Caml native-code compiler, version 3.11.0+beta1
Standard library directory:  .../lib/ocaml

And I compile my files in the following manner.

ocamlopt toto.mli
ocamlopt -shared -o bidon.cmxs bidon.ml
ocamlopt -o toto dynlink.cmxa toto.ml

My test runs as follows, with a behavior I did not expect:

./toto
no implementation available for Toto

Can you tell me what is missing in my experiment, or point me to an 
example that would be about the same size?

Yves