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
[Caml-list] dynlink
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-06 (06:01)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] dynlink
> Hi all,
> I'm using dynlink for my project and since now I always had really
> simple dependecies (each module dependes only to an other module).
> As things are getting more complicated I need to have one module
> that dependes by many others. My initial solution was to load the
> module, look at possible dependecies error and try to solve them. It
> works well for the simple case but it fails with multiple deps.
> Does anyone can show me how to get the list of (recursive) depcs given a
> module ? recursive as a module can depend by an other module that in
> turn dependes by many other ...
> something like
> let depslist = magicfunction filename in (* I get all recrusive deps or
fail *)
> List.iter (fun f -> Dynlink.loadfile f) (List.rev listdeps) (* I load
eveything in order *)

When loading failed because a dependency is missing , Dynlink is raising an
exception Unavailable_unit "xxx" or Linking_error (_,Undefined_global "xxx")
You can then try to load the corresponding module recursively :

(this should work, I have been using 2 years ago)

let rec load_module modname =
        Hashtbl.find modules modname
        Not_found ->
                Hashtbl.add modules modname ();
                Hashtbl.add are_loading modname ();
                current_module := ("Loading "^modname);
                Dynlink.loadfile (modname^".cmo");
                Hashtbl.remove are_loading modname;
                    Dynlink.Error(Dynlink.Unavailable_unit(depend)) |

Dynlink.Error(Dynlink.Linking_error(_,Dynlink.Undefined_global(depend))) as
e ->
                        if Hashtbl.mem are_loading depend then failwith
("Crossing with "^depend);
                        load_module depend;
                        Hashtbl.remove modules modname;
                        load_module modname

Nicolas Cannasse

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: