Skip to content
Generate Gtk3 bindings for OCaml
OCaml Haskell C C++ Shell Makefile Common Lisp
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


Automatic generation of GTK bindings for OCaml using GObject Introspection. Currently this project is in an highly experimental status.

This is a fork of haskell-gi.

The design of the generated APIs is heavily inspired by lablgtk.

Table of Contents



$ stack build

will download the needed dependencies and build the project.

Installing the core library

Enter the base-ocaml/gilablgtk3 directory, compile and install the library:

dune build
dune install

Generate the bindings

The easiest way is to use the script. The bindings will be generated inside the bindings folder.

Usage: [OPTION] LIB [LIB...]

Available libs are: glib gobject gio atk cairo pango gdkpixbuf gdk gtk

  -h, (help)     Display this help and exit
  -f, (full)     Generate every available library. The LIB arguments will be ignored.
  -i, (install)  After the library generation, it will install it using 'dune install'

Generally, you want to generate the bindings using:

$ ./ -f -i

This will generate and install every available library in the correct order. The order is important because some libraries depends on the previous ones.

Running the examples

Inside the examples directory there is a dune project containing some example programs you can run.

Assuming you have installed the GIGtk library, you can run them by:

$ cd examples
$ dune exec ./example-name.exe

Alternatively if you wish to run them without changing directory you can do:

$ dune exec --root examples ./example-name.exe

Running the project manually

First you have to define some environment variables:

  • BASE_OCAML_C: The generated libraries need to link against some C header files which are part of this library. By default they are inside base-ocaml/c. The env variable must point to this directory.
  • GI_INCLUDES: Some of the generated libraries depend on C header files of other (previously generated) libraries. This env variable is needed to tell dune where to find them. These headers are located inside bindings/LIB_NAME/include. So, for every dependency of the library you want to generate, GI_INCLUDES must contain -I`pwd`/bindings/LIB_NAME/include.

Example: If you wish to generate gio, which depends on glib and gobject, then GI_INCLUDES=-I`pwd`/bindings/GLib/include -I`pwd`/bindings/GObject/include

Once these env variables are exported, you can run the generator directly from stack using:

$ stack build && stack exec ocaml-gi-gtk-exe -- lib-name

The usage is:

Usage: ocaml-gi-gtk [-h] [-v] LIB
Available LIBs are: glib, gobject, gio, atk, cairo, pango, gdkpixbuf, gdk, gtk, gtksource

Adding a new library

The available libraries are listed inside app/Main.hs, so a new library must be defined there.

The name and version fields of Library are needed to correctly resolve the corresponding GIR file. The overrides file is an optional file used to change some (possibly incorrect) GIR attributes.

These attributes can be found in the haskell-gi's bindings directory . Inside every subdirectory there is a file containing the needed informations (girName, girVersion and girOverrides). The override file has to be copied from the haskell-gi's repository to the overrides directory.

You can’t perform that action at this time.