From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id C831ABC37 for ; Mon, 8 Feb 2010 17:03:38 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqEBAL7Eb0vRVdjHkGdsb2JhbACTOodLPAEBAQEJCQwHEwOuUoQeiHEBAQMFhE8EgyuIUw X-IronPort-AV: E=Sophos;i="4.49,431,1262559600"; d="scan'208";a="51978936" Received: from mail-px0-f199.google.com ([209.85.216.199]) by mail1-smtp-roc.national.inria.fr with ESMTP; 08 Feb 2010 17:03:38 +0100 Received: by pxi37 with SMTP id 37so6999146pxi.9 for ; Mon, 08 Feb 2010 08:03:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:from:date:x-google-sender-auth:message-id:subject:to:cc :content-type; bh=zanSnQV0kgQxDjGul3wMv2hQxMkKjR2GAIWf6HMncbo=; b=XMW3whwwoyRA8gQ5E4eGy5T150Rg4rDemPKmo7LdQVB+qa7G215Hh2ZpoAgOKWGrGy eeZw2hzNf6bznKSyTEEQ6kkhuNd6Z9VHRtiHWKywoZaI42PoNtLKjDAY0klEklxG/og9 Za4zJI3jTeEjqwRWJEi9gI+mAcWPM/f74rSvk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=X6k/I7nZLwtfx2mWpEH4K5cNcjM69EmvNLIkSdi8KsEP6hmaGBgBfMtUXxLd5BKhWA bUhzxaIAgP2q2+xKRRcaNTVvyszMAZ8QV2ffj80Xj5vZV+eMYd4plIOmsr5OhwHnPFDh 0yjtU8s3lscqNNoOkKndcF/rkBGVPqZVYX6hE= MIME-Version: 1.0 Sender: luca.de.alfaro@gmail.com Received: by 10.140.180.7 with SMTP id c7mr4634320rvf.21.1265645017133; Mon, 08 Feb 2010 08:03:37 -0800 (PST) In-Reply-To: References: <28fa90931002071813k7330ad34s7a2ec8b4cf1c3d11@mail.gmail.com> From: Luca de Alfaro Date: Mon, 8 Feb 2010 08:03:15 -0800 X-Google-Sender-Auth: 411e12554d0af7e0 Message-ID: <7b0bd61a1002080803n6cda4bc5g9eeb8d559538598f@mail.gmail.com> Subject: Re: [Caml-list] Re: How to wrap around C++? To: Michael Ekstrand Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=000e0cd1ab80a89c6d047f18f100 X-Spam: no; 0.00; ocaml:01 ocaml:01 extern:01 mlvalues:01 stub:01 extern:01 evidently:01 compiler:01 swig:01 swig:01 compiler:01 stubs:01 stubs:01 vice-versa:01 mlvalues:01 --000e0cd1ab80a89c6d047f18f100 Content-Type: text/plain; charset=ISO-8859-1 Thank you very much! I follow the general lines, but... > * Make sure no C++ exceptions leak to OCaml. > This will be next to impossible: the C++ code I need to wrap is huge, and I have no idea of what possible exceptions can be generated. I will have to try to see if there is a generic exception catcher. > * Wrap your OCaml includes in 'extern "C" { ... }" > Here, I am not sure what you mean. You mean, extern "C" { #include ... } ? > * Export all your stub functions with C linkage (extern "C") > Ok, evidently, I need to learn this extern "C" construct. > * Compiling is tricky, since the OCaml compiler driver doesn't know what > to do with C++. The Swig documentation[1] has a workaround for this, > useful even if you don't use Swig. > > Why would the Ocaml compiler driver need to know what to do with C++? The C++ I need to link to is rather huge, and I will need to compile it with its own build setup. Once that is built, I need to compile the stubs, the Ocaml, and link the three together (Ocaml, stubs, and C++), in native mode, but why would the Ocaml compiler need to deal with C++? Another question: I could also try to do the vice-versa, and use Ocaml as libraries from C++. Has anybody tried doing this? Is it easy to do? Luca --000e0cd1ab80a89c6d047f18f100 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you very much! =A0I follow the genera= l lines, but...
=A0
* Make = sure no C++ exceptions leak to OCaml.

This will be next to impossible: the C++ c= ode I need to wrap is huge, and I have no idea of what possible exceptions = can be generated. =A0I will have to try to see if there is a generic except= ion catcher.=A0
=A0
* Wrap your OCaml includes in= 'extern "C" { ... }"

Here, I am not sure what you mean. =A0You = mean,=A0

extern "C" {
#include= <caml/mlvalues.h>
...
}

?=A0
=A0
* Export all your s= tub functions with C linkage (extern "C")

Ok, evidently, I need to learn this extern= "C" construct.
=A0