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
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: 2008-11-26 (14:22)
From: Yves Bertot <Yves.Bertot@s...>
Subject: Tutorial example for nat dynlink

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 -----

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

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

------ 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:

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?