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 JAA22987; Tue, 6 Apr 2004 09:46:45 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA22985 for ; Tue, 6 Apr 2004 09:46:44 +0200 (MET DST) Received: from mail.rsise.anu.edu.au ([150.203.208.23]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i367kgYM012471 for ; Tue, 6 Apr 2004 09:46:43 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id 5B3592C0B for ; Tue, 6 Apr 2004 17:46:40 +1000 (EST) Received: from pulp.anu.edu.au (pulp.anu.edu.au [150.203.126.25]) by mail.rsise.anu.edu.au (Postfix) with ESMTP id 4DF9D2C0A for ; Tue, 6 Apr 2004 17:46:39 +1000 (EST) Received: by pulp.anu.edu.au (Postfix, from userid 1560) id 7F57D25B7AD; Tue, 6 Apr 2004 17:46:39 +1000 (EST) Date: Tue, 6 Apr 2004 17:46:39 +1000 From: Pietro Abate To: ocaml ml Subject: Re: [Caml-list] dynlink Message-ID: <20040406074639.GA12801@pulp.anu.edu.au> Mail-Followup-To: Pietro Abate , ocaml ml References: <20040406025129.GA8845@pulp.anu.edu.au> <006301c41b9c$3d475670$19b0e152@warp> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <006301c41b9c$3d475670$19b0e152@warp> X-Operating-System: GNU/Linux X-Organization: Research School of Information Science and Engineering (Australian National University) User-Agent: Mutt/1.5.5.1+cvs20040105i X-Scanned-By: AMaViS-ng/Claimv at mail.rsise.anu.edu.au X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pietro:01 abate:01 pietro:01 abate:01 caml-list:01 dynlink:01 2004:99 cannasse:01 hashtbl:01 hashtbl:01 printf:01 printf:01 dynlink:01 loadfile:01 failwith:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 63 tnx for your help. below the working code for future reference... On Tue, Apr 06, 2004 at 07:58:46AM +0200, Nicolas Cannasse wrote: > (this should work, I have been using 2 years ago) let modules = Hashtbl.create 17;; let are_loading = Hashtbl.create 17;; let load_path = ["."] ;; let find_in_path path name = let filename = (String.uncapitalize name) ^ ".cmo" in if not (Filename.is_implicit filename) then if Sys.file_exists filename then filename else raise Not_found else begin let rec try_dir = function [] -> raise Not_found | dir::rem -> let fullname = Filename.concat dir filename in if Sys.file_exists fullname then fullname else try_dir rem in try_dir path end let rec load_module modname = try Hashtbl.find modules modname with Not_found -> try Hashtbl.add modules modname (); Hashtbl.add are_loading modname (); Printf.printf "Loading: %s\n" modname ; Dynlink.loadfile (modname); (* register dynamic functions *) 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 (find_in_path load_path depend); Hashtbl.remove modules modname; load_module modname let _ = Dynlink.init(); load_module (find_in_path load_path "modulename") p -- ++ "All great truths begin as blasphemies." -George Bernard Shaw ++ Please avoid sending me Word or PowerPoint attachments. See http://www.fsf.org/philosophy/no-word-attachments.html ------------------- 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