From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=AWL,NO_REAL_NAME,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 1F3ACBBAF for ; Fri, 9 Jan 2009 09:47:02 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.37,238,1231110000"; d="scan'208";a="33489599" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 09 Jan 2009 09:47:02 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id n098l0k1029488 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 9 Jan 2009 09:47:01 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYAAEueZknPLfmwlGdsb2JhbACSYiKBDQEBAQEJCwgJEQWqdJAEhXQ X-IronPort-AV: E=Sophos;i="4.37,238,1231110000"; d="scan'208";a="22204796" Received: from parmail05.sgcib.com ([207.45.249.176]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 09 Jan 2009 09:47:00 +0100 X-IronPort-AV: E=Sophos;i="4.37,238,1231110000"; d="scan'208";a="28022565" Content-class: urn:content-classes:message MIME-Version: 1.0 X-MimeOLE: Produced By Microsoft Exchange V6.5 Subject: RE: [Caml-list] Shared libraries with ocamlopt callable from C(without main())? Date: Fri, 9 Jan 2009 09:44:31 +0100 Message-ID: <0172C3AE3A0E964797AF43E206C1048F015DD95C@FRCOR-EXMB06.europe.am.socgen> In-Reply-To: <49670917.3040103@gmail.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [Caml-list] Shared libraries with ocamlopt callable from C(without main())? Thread-Index: AclyM4zxhhIeKMdXSAutgLLs+03VlwAACp1A From: To: Cc: X-OriginalArrivalTime: 09 Jan 2009 08:44:32.0461 (UTC) FILETIME=[7E01AFD0:01C97236] X-NAI-Spam-Score: -2.5 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Miltered: at concorde with ID 49670F04.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocamlopt:01 callable:01 ocaml:01 ocaml:01 pointers:01 dllmain:01 bool:01 apientry:01 dllmain:01 argv:01 argv:01 matthieu:01 dubuget:01 ocamlopt:01 callable:01 The simplest way of achieving what you want might be the following: 1) Write the ocaml code you want to call. 2) register your caml functions via Callback.register 3) In your C code, define the callback values for each ocaml function, via = a macro like #define ACTION(actionname) \ static value *actionname##_closure =3D NULL; and fore each c function that wraps the caml call, call ACTION("camlfunctio= nname") before your c wrapping code. 4) define an initialization helper (to get the pointers to ocaml functions)= , something like #define INITACTION(actionname) \ actionname##_closure =3D caml_named_value(#actionname); 5) In your DLLMain function, you can have something like BOOL APIENTRY DllMain(HANDLE module, DWORD reason, void *reserved) { char * argv[2]; switch (reason) { case DLL_PROCESS_ATTACH: argv[0] =3D "--"; argv[1] =3D NULL; caml_startup(argv); INITACTION(analyze) INITACTION(updateBlob) ..... break; } return TRUE; }=20 This handles the C functions:(C Wrapper | C API of OCaml ) -> OCaml definin= g a C dll with the needed entries. You can use afterwards your langX -> ( C API of langX -> call above dll). If your langX can call directly C functions without the need of type conver= sions, this can do. If not, this approach might give you two dlls (langX -> C dll) and (C -> oc= aml) dll. If you want only one dll, I think this is only a linking issue, and can be = solved by inputing the C->ocaml , compiled ocaml and langX->C together to t= he linker. Hope this helps, Sincerely, Rabih Chaar -----Message d'origine----- De=A0: caml-list-bounces@yquem.inria.fr [mailto:caml-list-bounces@yquem.inr= ia.fr] De la part de Matthieu Dubuget Envoy=E9=A0: vendredi 9 janvier 2009 09:22 =C0=A0: caml-list@inria.fr Objet=A0: Re: [Caml-list] Shared libraries with ocamlopt callable from C(wi= thout main())? Ben Aurel a =E9crit : > I'm thinking about the possibility to use OCaml as an extension > language. If I wanted to call a OCaml function from langX I had to use > a C wrapper. > > langX -> ( C API of langX | C Wrapper | C API of OCaml ) -> OCaml > =20 Yes > But could somebody tell me if ( and maybe how ) this can be done. I made = some attempts, but > there is always a main() function involved. But this C wrapper would be a= shared library. > =20 Exactly. You can deliver your OCaml code as shared library, and then call it from any language that can call a shared library. Could you point out what problem you faced? Salutations Matt _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs This message and any attachments (the "message") are confidential, intended= solely for the addressee(s), and may contain legally privileged informatio= n.=20 Any unauthorised use or dissemination is prohibited.=20 E-mails are susceptible to alteration.=20 Neither Societe Generale Asset Management nor any of its subsidiaries or af= filiates shall be liable for the message if altered, changed or falsified.=20 =20 Find out more about Societe Generale Asset Management's proposal on www.sga= m.com =20 ********=20 =20 Ce message et toutes les pieces jointes (ci-apres le "message") sont confid= entiels et susceptibles de contenir des informations couvertes par le secre= t professionnel. Ce message est etabli a l'intention exclusive de ses destinataires. Toute utilisation ou diffusion non autorisee est interdite.=20 Tout message electronique est susceptible d'alteration. Societe Generale As= set Management et ses filiales declinent toute responsabilite au titre de c= e message s'il a ete altere, deforme ou falsifie.=20 Decouvrez l'offre et les services de Societe Generale Asset Management sur = le site www.sgam.fr