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 EAA16163; Thu, 20 Nov 2003 04:30:10 +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 EAA16217 for ; Thu, 20 Nov 2003 04:30:09 +0100 (MET) Received: from mail.mts-nn.ru (mail.mts-nn.ru [213.177.96.9]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hAK3U7106068 for ; Thu, 20 Nov 2003 04:30:07 +0100 (MET) Received: from tornado (cs1-ats25-dzer-221.dialup.mts-nn.ru [213.177.121.221]) by mail.mts-nn.ru (8.12.10/8.12.10) with SMTP id hAK3Twk1004438; Thu, 20 Nov 2003 06:30:00 +0300 Message-ID: <004001c3af17$20b46df0$dd79b1d5@tornado> From: "Kamil Shakirov" To: , References: <3FBC0177.1050307@cs.caltech.edu> Subject: Re: [Caml-list] Compiling a native code OCaml library into an .so? Date: Thu, 20 Nov 2003 06:33:37 +0300 Organization: niimash 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-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 dynamically:01 mismatches:01 runtime:01 ocamlopt:01 ocamlopt:01 -shared:01 dynlink:01 c's:01 dlopen:01 ideally:01 dynlink:01 malc:01 scaml:01 cmxa:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, > 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? Look at the http://www.boblycat.org/~malc/scaml/ -- Kamil. ------------------- 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