Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] interfacing C++ with OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] interfacing C++ with OCaml
> 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. 

Bon courage...

- Xavier Leroy
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: