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.4 required=5.0 tests=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 discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id DE217BC69 for ; Fri, 30 Mar 2007 01:27:02 +0200 (CEST) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.226]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2TNR1pb027661 for ; Fri, 30 Mar 2007 01:27:02 +0200 Received: by nz-out-0506.google.com with SMTP id l8so295160nzf for ; Thu, 29 Mar 2007 16:27:01 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=os85IsnW1EGn+jvL5yRVR2tqfXZzzncW3/OAZHA1kIH8M0mGeaRa9g+9VpUldoU5bTDikh2/JM80fTjbaUUJjnrOSf3Cn/6Y6sQOoBX4LnJ3X6/0VSs3iFnCBGxfBHRYB4REyofRPuZ0Kf+JPC8tBRctBpVL9LygX2uc43QFSeA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=oQ1m30nUxc588OcPF7UGHmD11ENJ2qB+jvYDIxNjC4wI8ClXicV3/EgA4W2UXasRMQxBcZOb9dqSGspzVyl9iayTPBOKi62zCKysbqkaiQb0lQQBqsidMhqYTYfuUpvZL8nQgp96u0NIjIc7bNwxRPrlJk8C5y17QdT7Vlzmydk= Received: by 10.114.133.1 with SMTP id g1mr503914wad.1175210820322; Thu, 29 Mar 2007 16:27:00 -0700 (PDT) Received: by 10.115.59.8 with HTTP; Thu, 29 Mar 2007 16:26:59 -0700 (PDT) Message-ID: <1ffe809c0703291626g4b385bd2qee9f9b5d72e3b95b@mail.gmail.com> Date: Thu, 29 Mar 2007 20:26:59 -0300 From: "Pablo Polvorin" To: "Joel Reymont" Subject: Re: [Caml-list] OCaml and C code in a dynamic library Cc: "Caml List" In-Reply-To: <2A0CAD37-6509-4FD8-A5C0-D704C7E17E2A@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <2A0CAD37-6509-4FD8-A5C0-D704C7E17E2A@gmail.com> X-j-chkmail-Score: MSGID : 460C4B45.001 on discorde : j-chkmail score : XX : 0/20 2 0.000 -> 2 X-Miltered: at discorde with ID 460C4B45.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 wrappers:01 ocaml:01 libcamlrun:01 runtime:01 -fpic:01 libcamlrun:01 runtime:01 lib:01 argv:01 lib:01 argv:01 -fpic:01 flags:01 ocamlc:01 Hi Joel, i recently make a dynamic library including c++ wrappers to an ocaml module, to be loaded as a SCA component by apache tuscany. The first problem was that i have a 64b architecture, and in order to link against libcamlrun in shared mode, a recompilation of the runtime with -fPIC flag was necessary. I called the resulting library libcamlrun_shared, to not confuse it with the original one. Also you have to initialize the ocaml runtime from whiting you library.., and for my best knowledge it is necessary to pass the path to you .so to the caml_main function, like: #define LIB_DIR "/home/pablo/ocaml/tproject/deploy/TuscanyCalculator" static char *argv[] = { LIB_DIR "/libTuscanyCalculatorImpl.so", LIB_DIR "/libTuscanyCalculatorImpl.so", NULL }; caml_main (argv); The way that work for my is to compile the c code with -c -fPIC flags, compile the ocaml modules also with -c , and then link all the object codes together with ocamlc -linkall -custom -cclib "-fPIC -shared ... and include the libraries you need ( -lcamlrun_shared -ltermcap in my system) I think the best is to look at the makefile of the ocaml module for the aol server http://www.crystalballinc.com/vlad/software/ or the apache mod_ocaml http://merjis.com/developers/mod_caml , a lite more complex makefile. also, look at these previous post in this area: http://caml.inria.fr/pub/ml-archives/caml-list/2002/09/0d8daa135bd30302f1ebf30daf9a0ed9.en.html http://caml.inria.fr/pub/ml-archives/caml-list/2002/01/44d30c5454106646098bf00977c66796.en.html http://caml.inria.fr/pub/ml-archives/caml-list/2001/12/e9e89dadd773729481bf8446f1b73b64.en.html and also the manual pages http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html regards, pablo. 2007/3/29, Joel Reymont : > Has anyone succeeded in wrapping OCaml code in a dynamic library for > use in C? > > I can build a static OCaml library without any problems but when I > try to package that and some other C code in a dynamic library I get > errors like this on Mac OSX: > > /usr/bin/ld: ./libfib.a(fibcaml.o) has local relocation entries in > non-writable section (__TEXT,__text) > > Thanks, Joel > > -- > http://wagerlabs.com/ > > > > > > _______________________________________________ > 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 > -- Pablo Polvorin