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
Wrapping C++ in Ocaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-01-02 (13:11)
From: micha <micha-1@f...>
Subject: Re: [Caml-list] Wrapping C++ in Ocaml?
Erik de Castro Lopo schrieb:
> Hi all,
> I have wrapped a C library for use with Ocaml and didn't find 
> the task too daunting. I have now found a C++ library that would
> be useful, but the Ocaml ORA book makes no mention of wrapping
> C++ libraries.
you can only wrapp via C - functions

> Has anyone got any experience wrapping C++ libraries in Ocaml?
> Is it possible? Painful but doable? Too painful to think about?
I have done it a few times, it's much typing :-)
you must write a c function for the methods of the class you want to 
wrap and give them a pointer to the c++ class, so you can call the 
method there. Often you define on the c++ side an adapter class which 
delegates method calls to the ocaml side (f.e. when wrapping events from 
and to c++/ocaml). For big libraries it's a neverending task without 
more tools.
There is the platinum framework (on sourceforge), a c++ class lib with a 
little gui. This lib compiles for win32, Linux, WinCE and qnx, I have 
done some wrapping to the gui part, together with the event handling and 
it works very nice (if you want to read it as an example).

> Any pointers or advice appreciated.
Python, Ruby and Perl all have wrappers for QT and they use tools to 
generate the C interface I think. Maybe worth to look at...