Foreign Function Interface
Interop with C/C++ is the most natural option for OCaml, since the runtime is partially written in C.
- ctypes: Modern library for binding to C libraries using pure OCaml. You should always try to bind to C code using ctypes before trying the older method.
- ppx_cstubs: Possibly the easiest solution for FFI with C, allowing you to place C code in your OCaml files. Everything else is taken care of for you.
- cstruct: Library to access C-style structures from OCaml. It comes with a ppx preprocessor and variants for lwt and async.
- The older way of binding to C code is to create stubs in C which call functions in the OCaml runtime. This method is error prone, and you’re advised to stay away from it unless it’s absolutely necessary.
- ocaml-main-program-in-c – Example build system for making mixed C/Ocaml binaries where the main program is in C.
- Py: Library for interacting with Python 3.5 using Ctypes.
- Pyml: Library for interacting with python. Uses C stubs.
- lymp: Another library for interacting with Python, this one using a Python process.
- rust-ocaml-derive: provides an FFI with Rust. Works on both the OCaml-to-Rust and Rust-to-OCaml directions.
- Modular foreign function bindings with ctypes.