20+ ways to build an executable with foreign libs

Foreign libs can be linked into OCaml executables in a variety of ways. The pertinent info is distributed across several topics in the manual. So I put together a suite of 20-some MWEs demonstrating the options:

  • emitting native or bytecode executables
  • vm executables: freestanding or dependent on ocamlrun
  • using a static or dynamic stublib
  • linking the stublib against static or shared foreign libs
  • putting lib deps directly on the cmd line v. using -cclib or -dllib

All demos use a very simple foreign lib (in C) and stublib, and the builds are expressed in a few relatively simple makefiles.

This could be used as the basis of a proper tutorial, but I’m not sure I’ll get around to that. The main goal is to save you a little time if you want to do some exploratory programming.

(Oh crap, I forgot to update the docs. The make target names are a little different. Read the makefiles. :wink: )

9 Likes