The Binding Generator C➔Haskell
|  | Next

## The Binding Generator C➔Haskell

### Manuel Chakravarty

`<chak@cse.unsw.edu.au>`

November 2007

Abstract

C➔Haskell is an interface generator that simplifies the development of Haskell bindings to C libraries. The tool processes existing C header files that determine data layout and function signatures on the C side in conjunction with Haskell modules that specify Haskell-side type signatures and marshaling details. Hooks embedded in the Haskell code signal access to C structures and functions -- they are expanded by the interfacing tool in dependence on information from the corresponding C header file. Another noteworthy property is the lightweight nature of the approach.

More background information is available in a research paper discussing C➔Haskell, which is at http://www.cse.unsw.edu.au/~chak/papers/papers.html#c2hs. However, this paper does not cover the more recent advanced features such as function hooks and conditional compilation.

## Installation

It follows a brief discussion of the installation from source. There is, however, a file `INSTALL` in the source distribution, which is more frequently updated and should be consulted in any case.

### Where is the Source?

The master site of C➔Haskell is at http://www.cse.unsw.edu.au/~chak/haskell/c2hs/. It has all the latest information and sources. Furthermore, it explains how to get access to the C➔Haskell Darcs repository and has references to pre-compiled binaries.

### What Else Do I Need?

You need a Haskell system supported by C➔Haskell. Currently, this is only the Glasgow Haskell Compiler (GHC), which you can obtain from http://haskell.org/ghc/. Furthermore, you need the Haskell package system Cabal. See the `INSTALL` file for details on supported versions.

To build the documentation, you will also need the SGML Tools, which you find at your nearest sunsite or Linux mirror or at ftp://ftp.lip6.fr/pub/sgml-tools/. On an up-to-date Linux system, the tools are probably already installed.

### I Got Everything, and Now?

The short answer is

    $ tar -xzf package.tar.gz      # unpack the sources
    $ cd package                   # change to the toplevel directory
    $ runghc Setup.hs configure    # configure the build system
    $ runghc Setup.hs build        # build everything
    [ Become root if necessary ]
    $ runghc Setup.hs install      # install c2hs

In the `INSTALL` file, there are more details.

Optionally, you can build the documentation by issuing `make doc` and install it with `make install-doc`.

|  | Next
|  | Usage of C➔Haskell