<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/2bd282060b80b73e41fc932d3d2060e1"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-07-05T09:46:15"
  subject="Re: [Caml-list] interfacing C++ with OCaml"
  prev="2002/07/fa6f4b49227ef840303e76915d7f82e0"
  next="2002/07/dc781b0623ef875df91c3aafad01e44c"
  prev-in-thread="2002/07/a8750e6e5c21abd91d03e3547ae8f043"
  prev-thread="2002/07/47ffc0354acdc6c8f3c1f074c19ba9d0"
  next-thread="2002/07/e8cfed320dd386bfa41ec4a2c3085837"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] interfacing C++ with OCaml">
<msg 
  url="2002/07/a8750e6e5c21abd91d03e3547ae8f043"
  from="Thierry SALSET &lt;ts@c...&gt;"
  author="Thierry SALSET"
  date="2002-07-04T17:21:16"
  subject="[Caml-list] interfacing C++ with OCaml">
<msg 
  url="2002/07/2bd282060b80b73e41fc932d3d2060e1"
  from="Xavier Leroy &lt;xavier.leroy@i...&gt;"
  author="Xavier Leroy"
  date="2002-07-05T09:46:15"
  subject="Re: [Caml-list] interfacing C++ with OCaml">
</msg>
</msg>
</thread>

<contents>
&gt; I used Camlidl to help me interface C functions and datatypes with OCaml
&gt; under Unix but now I would like to interface some existing (written by
&gt; others) C++ classes and methods with OCaml. I am not a C++ programmer
&gt; and I'm a little bit lost. Can Camlidl be of some help ? Should I write
&gt; a C layer between C++ and OCaml ?

This is a reasonable option.  Once you have a pure C API for the
C++ code, you can use CamlIDL as usual.  

CamlIDL itself doesn't have any kind of direct support for C++.  Well,
it supports COM interfaces, which correspond to a very small subset of
C++ classes, but I doubt this can help you, unless the C++ code of
interest is already structured as COM interfaces.

The other alternative is to hand-write Caml wrappers that call
directly the C++ code, without going through C.  I believe you can
write those wrappers in C++ if you're careful to declare the entry points
(the functions that Caml will call) "extern "C"".

Some of the features of C++ might be used to wrap the Caml runtime API (the
functions and macros provided by &lt;caml/mlvalues.h&gt;, etc) in a more
C++-friendly style, see e.g.
         http://caml.inria.fr/archives/199704/msg00029.html 

Bon courage...

- Xavier Leroy
-------------------
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

</contents>

</message>

