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 AAA10003; Thu, 20 Nov 2003 00:49:16 +0100 (MET) 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 AAA09966 for ; Thu, 20 Nov 2003 00:49:15 +0100 (MET) Received: from swordfish.cs.caltech.edu (swordfish.cs.caltech.edu [131.215.44.124]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hAJNnE115161 for ; Thu, 20 Nov 2003 00:49:14 +0100 (MET) Received: from cs.caltech.edu (wasco.cs.caltech.edu [131.215.44.173]) by swordfish.cs.caltech.edu (Postfix) with ESMTP id 5D35EDF242 for ; Wed, 19 Nov 2003 15:49:13 -0800 (PST) Message-ID: <3FBC0177.1050307@cs.caltech.edu> Date: Wed, 19 Nov 2003 15:49:11 -0800 From: Aleksey Nogin Reply-To: caml-list@inria.fr, onlynews@metaprl.org Organization: California Institute of Technology, Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031030 X-Accept-Language: ru, en-us, en MIME-Version: 1.0 Newsgroups: local.metaprl To: caml-list@inria.fr Subject: [Caml-list] Compiling a native code OCaml library into an .so? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; dynamically:01 mismatches:01 runtime:01 ocamlopt:01 ocamlopt:01 -shared:01 dynlink:01 c's:01 dlopen:01 ideally:01 dynlink:01 626:99 cmxa:01 cmxa:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello all, I am wondering - is it possible to compile a native code OCaml library into an dynamic library (.so) and then link an OCaml program against it, or dynamically load it from an OCaml program? My (very shallow) understanding of how this is supposed to work suggests that it should not be too hard to implement (at least if we do not insist on detecting version mismatches at runtime). We would need: 1) A flag to ocamlopt that would tell it to compile to ".cmxa + .so" instead of ".cmxa + .a". Given such a flag, ocamlopt would a) Create an assembly file defining _init function that would call the initialization functions of all the modules and add that file to the list of things to be compiled in. b) Add -shared flag to the ld call. 2) When compiling a program with ocamlopt, if one of the arguments is a .cmxa, then look for both .a and .so and pass the right one to ld. 3) Have a function somewhere (Dynlink module?) that's a wrapper for the C's dlopen function. 4) Ideally - have a function somewhere (Dynlink module?) that would try loading a .cma when running in bytecode and would try loading an .so when running in native code. Am I missing any serious difficulties here? Are there any plans to add something like this to OCaml? -- Aleksey Nogin Home Page: http://nogin.org/ E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal) Office: Jorgensen 70, tel: (626) 395-2907 ------------------- 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