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
Creating wrappers for C libraries
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-12-08 (06:36)
From: Chris King <colanderman@g...>
Subject: Re: [Caml-list] Creating wrappers for C libraries
On 12/7/06, Erik de Castro Lopo <> wrote:
> I was wondering if there was any semi-automated too for creating
> Ocaml bindings for C libraries.

I recently discovered that SWIG ( supports O'Caml
(though I haven't yet used it myself).  If you're looking for speed
though it may not be the best choice since all C types are mapped to
one variant type in O'Caml.  You can find O'Caml-specific docs here:

I presume you're looking to wrap libsndfile...  I've wrapped a few
similar libraries manually with very few problems.  The libsndfile API
looks to me like it should be fairly straightforward to wrap thanks to
O'Caml's Bigarrays (plus you'll have lots of cut & paste).

Start by writing a few simple integer, string, or array functions for
O'Caml in C to get a feel for the API without having to worry about
custom blocks and such.  The curses wrapper in chapter 18 of the
O'Caml manual is also a very good starting point.  The custom block
from that example can be used nearly verbatim for many C structures
(such as SNDFILE *).  I can provide you with the source of a couple
other small wrappers if you like.

Hope this helps,