Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Wrapping C++ in Ocaml?

74 views
Skip to first unread message

Erik de Castro Lopo

unread,
Jan 2, 2007, 5:34:56 AM1/2/07
to caml...@yquem.inria.fr
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.

Has anyone got any experience wrapping C++ libraries in Ocaml?
Is it possible? Painful but doable? Too painful to think about?

Any pointers or advice appreciated.

Cheers,
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"I consider C++ the most significant technical hazard to the survival
of your project and do so without apologies." -- Alistair Cockburn

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

micha

unread,
Jan 2, 2007, 8:13:18 AM1/2/07
to Erik de Castro Lopo
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...

cheers,
Michael

Dmitry Bely

unread,
Jan 2, 2007, 9:59:13 AM1/2/07
to caml...@yquem.inria.fr
On 1/2/07, Erik de Castro Lopo <mle+...@mega-nerd.com> wrote:

> Has anyone got any experience wrapping C++ libraries in Ocaml?
> Is it possible? Painful but doable? Too painful to think about?
>
> Any pointers or advice appreciated.

Swig?

http://www.swig.org

- Dmitry Bely

Anne.P...@sophia.inria.fr

unread,
Jan 10, 2007, 3:15:30 AM1/10/07
to
Erik de Castro Lopo wrote :

> Has anyone got any experience wrapping C++ libraries in Ocaml?

I did it some time ago, and I wrote a small tutorial about it :
http://www-sop.inria.fr/everest/personnel/Anne.Pacalet/camltop.php
Unfortunatly for you, it is in french, but maybe it can help anyway...
It explains both how to call C++ for caml and to call ocaml from C++.

Hope this will help.

Anne.

0 new messages