Jump to:  OMake Home • Guide Home • Guide (single-page) • Contents (short) • Contents (long)
Index:  All • Variables • Functions • Objects • Targets • Options

Chapter 17  Bindings and dynamic libraries

This feature will be introduced in version

A binding is a the glue code that provides an interface between code written in two different languages. In this section, we'll look specifically at OCaml/OMake bindings for C code. That is, the code to be used is written in C, and the user of the code is an OCaml or OMake program.

OMake provides tools to produce bindings automatically, given the following information:

Usually, a binding is used to provide an interface to a dynamically-linked library. The binding generated by OMake is also compiled for dynamic linking. Using the GTK+ 2.0 binding as an example, there are three layers in the implementation.

Bindinggtk.ml, gtk_bindings.ml, gtk_bindings.c (compiled to libgtk_bindings.so)
Library-lgtk-x11-2.0, -lgdk-x11-2.0, ...

The application is linked with the binding and the original library. For OCaml programs, this is normally done at compile time. For OMake programs that use the binding, the library is dynamically loaded (with dlopen(3)).

The process of constructing a binding is mostly automatic; OMake reads a header file constaining declarations for the values in the binding and produces the files xxx.ml, xxx_bindings.ml, and xxx_bindings.c. However, the programmer needs to specify what values are to be part of the binding. In some cases, the programmer may wish to implement some additional code to simplify the use of the code.

The general process is described in the the binding for GTK+ 2.0 (a graphics windowing binding), because it illustrates nearly all of the features of the binding.

Jump to:  OMake Home • Guide Home • Guide (single-page) • Contents (short) • Contents (long)
Index:  All • Variables • Functions • Objects • Targets • Options