# Generating static and portable executables with OCaml

**URL:** <https://discuss.ocaml.org/t/generating-static-and-portable-executables-with-ocaml/8405>\
**Category:** Community\
**Tags:** ocaml\
**Created:** [September 2, 2021, 1:15pm UTC](https://discuss.ocaml.org/t/generating-static-and-portable-executables-with-ocaml/8405 "2021-09-02T13:15:32Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![OCamlPro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ocamlpro/32/2011_2.png) [@OCamlPro](https://discuss.ocaml.org/u/OCamlPro)\
**Post date:** [September 2, 2021, 1:15pm UTC](https://discuss.ocaml.org/t/generating-static-and-portable-executables-with-ocaml/8405/1 "2021-09-02T13:15:32Z")

</div>

Hi everyone,

It has been a few times now that we have been tasked to generate portable binaries for different projects. Over time, we have gathered quite some know-how and, seeing the question frequently arise in the community, we decided to share this experience.

You can find the article written by Louis Gesbert on[the OCamlPro blog](https://www.ocamlpro.com/2021/09/02/generating-static-and-portable-executables-with-ocaml/)

> Distributing OCaml software on opam is great (if I dare say so myself), but sometimes you need to provide your tools to an audience outside of the OCaml community, or just without recompilations or in a simpler way.
> 
> However, just distributing the locally generated binaries requires that the users have all the required shared libraries installed, and a compatible libc. It’s not something you can assume in general, and even if you don’t need any C shared library or are confident enough it will be installed everywhere, the libc issue will arise for anyone using a distribution based on a different kind, or a little older than the one you used to build.
> 
> There is no built-in support for generating static executables in the OCaml compiler, and it may seem a bit tricky, but it’s not in fact too complex to do by hand, something you may be ready to do for a release that will be published. So here are a few tricks, recipes and advice that should enable you to generate truly portable executables with no external dependency whatsoever. Both Linux and macOS will be treated, but the examples will be based on Linux unless otherwise specified.

Don’t hesitate to share your thoughts with us, have a good reading!

---

_[View the full topic](https://discuss.ocaml.org/t/generating-static-and-portable-executables-with-ocaml/8405)._
