Plasma GitLab Archive
Projects Blog Knowledge

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:

  • A list of functions and values to be exported (that is, to be directly callable/accessible to OCaml program),
  • a list of structures that should be automatically expanded so that the fileds are directly accessible in the OCaml program (all other values are treated as opaque pointers),
  • a list of enumerations to be exported (enumeration values are exported as integers).
  • a set of callback functions that can be used to make upcalls from C code to the OCaml code.

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.

LayerFiles,, gtk_bindings.c (compiled to
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,, 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
This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml