From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA15741; Tue, 6 Apr 2004 08:01:44 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id IAA15878 for ; Tue, 6 Apr 2004 08:01:43 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from postfix3-2.free.fr (postfix3-2.free.fr [213.228.0.169]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3662Xjq019678 for ; Tue, 6 Apr 2004 08:02:33 +0200 Received: from warp (chateaudeau-4-82-225-176-25.fbx.proxad.net [82.225.176.25]) by postfix3-2.free.fr (Postfix) with SMTP id 8BD22D633; Tue, 6 Apr 2004 08:01:39 +0200 (CEST) Message-ID: <006301c41b9c$3d475670$19b0e152@warp> From: "Nicolas Cannasse" To: "Pietro Abate" , "ocaml ml" References: <20040406025129.GA8845@pulp.anu.edu.au> Subject: Re: [Caml-list] dynlink Date: Tue, 6 Apr 2004 07:58:46 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 dynlink:01 dynlink:01 dependecies:01 dependecies:01 deps:01 deps:01 loadfile:01 recursively:01 hashtbl:01 hashtbl:01 loadfile:01 failwith:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 60 > 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