Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 =
    try
        Hashtbl.find modules modname
    with
        Not_found ->
            try
                Hashtbl.add modules modname ();
                Hashtbl.add are_loading modname ();
                current_module := ("Loading "^modname);
                Dynlink.loadfile (modname^".cmo");
                Hashtbl.remove are_loading modname;
            with
                    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

Regards,
Nicolas Cannasse

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners