From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 5D4FEBBAF for ; Tue, 15 Dec 2009 15:50:09 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0BAIIwJ0vRVdvRkGdsb2JhbACQLIFuiGY/AQEBAQkJDAcTA6xrgTGFX4hjAQIDBYQmBI0m X-IronPort-AV: E=Sophos;i="4.47,400,1257116400"; d="scan'208";a="38656316" Received: from mail-ew0-f209.google.com ([209.85.219.209]) by mail2-smtp-roc.national.inria.fr with ESMTP; 15 Dec 2009 15:50:09 +0100 Received: by ewy1 with SMTP id 1so5009956ewy.8 for ; Tue, 15 Dec 2009 06:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=9C3/s4/AGgs15CQuTTCMVg4VpwLPD+1vHk/xW21vYkI=; b=KFkcVUi11cNFDqe+0hbKXLkV3UmddZJ8m2dcBgpOcUlRrW+3yFibZMohfLgJ6tjsN4 s5HJNSZpDSZ/PfFJ93RuhSEcdTJeKLdCdXRnVNpV4xhzmuFKIES9IOx5PwjEd6+Ne937 d0g+N/RZmMdR9Ozvl9XNqaCTeP7udYkBAyzSY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:content-transfer-encoding; b=mRkIYswjkjyNaBAU95BDUhsiyVGm74stwiizFdcMMJ6V/Sn2WElgvLZJR5+TK3UKx3 tCkP+PMAg4VqY7YY5Ltdzl0llMBrzK1u2Swa9Fx4VubFEXnX3eGHIgWTzE7jmeg5PWpb 04XdBN3vHkvtyoJLPfHARfHEkfdfdbKdBmVsM= MIME-Version: 1.0 Received: by 10.213.48.207 with SMTP id s15mr5184456ebf.8.1260888605303; Tue, 15 Dec 2009 06:50:05 -0800 (PST) Reply-To: kybic@fel.cvut.cz In-Reply-To: References: Date: Tue, 15 Dec 2009 15:50:05 +0100 Message-ID: <7a9cb3950912150650k5ef8d6a6uf125d035876cdc8d@mail.gmail.com> Subject: Re: [Caml-list] linking errors involving cpp files From: Jan Kybic To: Aaron Bohannon Cc: OCaml List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; cpp:01 cpp:01 ocaml:01 ocaml:01 swig:01 swig:01 stub:01 stub:01 extern:01 mlvalues:01 alloc:01 stdio:01 const:01 camlparam:01 val:01 On Tue, Dec 15, 2009 at 2:50 PM, Aaron Bohannon wr= ote: > > Thanks for the tip. =A0This does resolve the missing caml symbols (even > when naming the file with a cpp extension). =A0However, my real program > actually uses some C++ features. =A0I think I could convert it to a real > C program, but I assumed there would be some other way. > What you can do is to create a thin C layer between your Ocaml and C++ code= . I am including a very simple code - an interface to the Cubpack library in Ocaml. If your interface is big, you might try some of the authomatic builders like SWIG (http://www.swig.org) which I understand can wrap C++ classes for use in Ocaml. Jan --=20 ------------------------------------------------------------------------- Jan Kybic tel. +420 2 2435 5721 http://cmp.felk.cvut.cz/~kybic ICQ 20056945 // stub to call Cubpack++ integration routines from Ocaml // // // Jan Kybic, February 2004 // $Id: cubpack_stub.cc 322 2004-02-06 18:03:01Z jkybic $ extern "C" { #include #include #include #include } #include #include // This code is NOT thread safe // There is nothing to do about it except change Cubpack++ static value ocamlCallback ; // Call a Ocaml function with two arguments u,v real evalOcaml(const Point& p) { CAMLparam0() ; double z ; CAMLlocal3(ou,ov,oz) ; ou=3Dcopy_double(p.X()) ; ov=3Dcopy_double(p.Y()) ; oz=3Dcallback2(ocamlCallback,ou,ov) ; z=3DDouble_val(oz) ; CAMLreturn(z) ; } static double doIntegrate(double a, double r,int m) { CAMLparam0() ; Point p1(0.0,0.0), p2(0.0,1.0), p3(1.0,0.0); TRIANGLE T(p1,p2,p3); CAMLreturn (Integrate(evalOcaml,T)) ; } extern "C" // parameters: absolute and relative error bounds, maximum number // of evaluations, the function to evaluate value cubpackIntegrateTriangle (value a,value r,value m,value f) { CAMLparam4(a,r,m,f) ; // register for GC CAMLlocal1(z) ; register_global_root(&ocamlCallback) ; ocamlCallback=3Df ; z=3Dcopy_double(doIntegrate(Double_val(a),Double_val(r),Int_val(m))) ; remove_global_root(&ocamlCallback) ; CAMLreturn(z) ; } // end of cubpack_stub.cc