caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: Thierry SALSET <ts@cermics.enpc.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] interfacing C++ with OCaml
Date: Fri, 5 Jul 2002 11:46:12 +0200	[thread overview]
Message-ID: <20020705114612.C16273@pauillac.inria.fr> (raw)
In-Reply-To: <20020704.192114.115911667.ts@cassis.enpc.fr>; from ts@cermics.enpc.fr on Thu, Jul 04, 2002 at 07:21:14PM +0200

> I used Camlidl to help me interface C functions and datatypes with OCaml
> under Unix but now I would like to interface some existing (written by
> others) C++ classes and methods with OCaml. I am not a C++ programmer
> and I'm a little bit lost. Can Camlidl be of some help ? Should I write
> 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 <caml/mlvalues.h>, 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


  reply	other threads:[~2002-07-05  9:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-04 17:21 Thierry SALSET
2002-07-05  9:46 ` Xavier Leroy [this message]
2004-07-15 13:31 [Caml-list] Interfacing C with Ocaml Julius

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020705114612.C16273@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=ts@cermics.enpc.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).