package camlid

  1. Overview
  2. Docs
OCaml library for generating C stubs

Install

dune-project
 Dependency

Authors

Maintainers

Sources

camlid-0.2.tbz
sha256=fd6fd1319380810e5065ae06d9415d91cbac637d696345d3cca0cd34bfdc2e44
sha512=028b6a4aa1bef1a88400776c93205b8839f98e75745e14cd4312564258218482ee77605eaed7b23a97eea81cc64923ea0bed0ac5fe5703e5d4edfaeec140c45d

Description

Published: 11 Dec 2025

README

camlid

Camlid is a C binding generator for OCaml. Its interface is not yet stable.

The description is similar to the extension of IDL found in CamlIDL, but it is a DSL in OCaml and it removes the interface language part of IDL. Moreover it tries to keep a core simple and generic and uses predefined helpers for common types and patterns. It supports automatic unboxing, untagging when possible. The ownership of the allocated memory after the call to a stubbed C function can be specified.

C11 is required.

Documentation

Quick Example

Suppose the following header (alib.h):

void f_input(int);
void f_output(int *);
int f_with_res();
void f_no_arg_no_result();

The following OCaml program produces a basic_stub.c and basic.ml file.

 open Camlid
open Helper

let () = Generate.to_file "basic"
 ~headers:["alib.h"]
 [
   func "f_input" [ input int_trunc];
   func "f_output" [ output (ptr_ref int_trunc)];
   func "f_with_res" [] ~result:int_trunc;
   func "f_no_arg_no_result" [];
 ]

Then one just need to write basic.mli with the documentation:

 (** {2 Alib API} *)

(** set important global information *)
val f_input: int -> unit

(** get important global information *)
val f_output: unit -> int

(** get another very important global information *)
val f_with_res: unit -> int

(** do something really important *)
val f_no_arg_no_result: unit -> unit

Dependencies (3)

  1. ocaml >= "4.11"
  2. fmt >= "0.10.0"
  3. dune >= "3.19"

Dev Dependencies (1)

  1. odoc with-doc

Used by

None

Conflicts

None