# Ocaml cross compiler?

**URL:** <https://discuss.ocaml.org/t/ocaml-cross-compiler/1494>\
**Category:** Ecosystem\
**Created:** [January 28, 2018, 10:10am UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494 "2018-01-28T10:10:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leff\_Ivanov](https://avatars.discourse-cdn.com/v4/letter/l/53a042/32.png) [@Leff\_Ivanov](https://discuss.ocaml.org/u/Leff_Ivanov)\
**Post date:** [January 28, 2018, 10:10am UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/1 "2018-01-28T10:10:44Z")

</div>

Hello, what is the state of cross-compilation in Ocaml world? By cross-compilation I mean being compiling Ocaml code on for example some Windows or Linux system and targeting some other systems like Mac OSX. Is there ready to use toolchain builds that is able to cross-compile? Or do I need to build one myself?

---

<div class="post-metadata">

**Author:** ![bobbypriambodo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bobbypriambodo/32/179_2.png) [@bobbypriambodo](https://discuss.ocaml.org/u/bobbypriambodo)\
**Post date:** [January 28, 2018, 11:00am UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/2 "2018-01-28T11:00:31Z")

</div>

Dune, the OCaml build system, is adding cross-compilation in the 1.0+beta17 version. Unfortunately there were some issues so it would seem that the release is still postponed on opam and github. See the following thread for more on that.

> [@ANN: dune (jbuilder) 1.0+beta17](https://discuss.ocaml.org/t/ann-dune-jbuilder-1-0-beta17/1474):
>
> On behalf of the dune development team, I’d like to announce the 17 beta. Let me first make yet another reminder that the build system formerly named as jbuilder is now called dune. As of now, this poses no changes to users. However, the 1.0 release will make the old name obsolete. We will provide a migration tool to automate the transition. As for this release, I’ve replicated the detailed change log below. I will not make a usual short summary of the release, because I’ve prepared an entire …

The [docs about how to use it](http://jbuilder.readthedocs.io/en/latest/advanced-topics.html#cross-compilation) is already live, but I’m still not really sure how it works.

---

<div class="post-metadata">

**Author:** ![rgrinberg](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rgrinberg/32/40_2.png) [@rgrinberg](https://discuss.ocaml.org/u/rgrinberg)\
**Post date:** [January 29, 2018, 10:09am UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/3 "2018-01-29T10:09:55Z")

</div>

I have a plan to write a blog post explaining the cross compilation support in dune and the opam-cross-x repos a little better. It’s not my first priority currently, but expect such a thing post February.

---

<div class="post-metadata">

**Author:** ![jaredly](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jaredly/32/54_2.png) [@jaredly](https://discuss.ocaml.org/u/jaredly)\
**Post date:** [October 7, 2018, 12:54am UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/4 "2018-10-07T00:54:13Z")

</div>

I’m still not sure how to do this…

---

<div class="post-metadata">

**Author:** ![borisd](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/borisd/32/3965_2.png) [@borisd](https://discuss.ocaml.org/u/borisd)\
**Post date:** [June 22, 2019, 5:39pm UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/5 "2019-06-22T17:39:46Z")

</div>

Have there been new developments on this front?

---

<div class="post-metadata">

**Author:** ![dmbaturin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dmbaturin/32/2074_2.png) [@dmbaturin](https://discuss.ocaml.org/u/dmbaturin)\
**Post date:** [June 28, 2019, 9:15pm UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/6 "2019-06-28T21:15:08Z")

</div>

I’ve experimented with non-native build targets quite a bit lately, and opam-cross-windows was a really great experience. After following their readme to the letter (save for an opam pin step that is no longer needed), I can build windows executables with just “OCAMLFIND\_TOOLCHAIN=windows dune build”.

---

<div class="post-metadata">

**Author:** ![Dmitry\_Ponyatov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dmitry_ponyatov/32/1956_2.png) [@Dmitry\_Ponyatov](https://discuss.ocaml.org/u/Dmitry_Ponyatov)\
**Post date:** [January 23, 2020, 10:07pm UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/7 "2020-01-23T22:07:54Z")

</div>

What about embedded targets like Cortex-M (STM32F3/F4)?  
How much memory should it have to have to run OCaml-compiled programs?

---

<div class="post-metadata">

**Author:** ![ivg](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ivg/32/103_2.png) [@ivg](https://discuss.ocaml.org/u/ivg)\
**Post date:** [January 24, 2020, 6:50pm UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/8 "2020-01-24T18:50:15Z")

</div>

You may find this [page](http://www.algo-prog.info/ocapic/web/index.php?id=ocapic) interesting. To summarize, with _a lot of work_ you can make a subset of OCaml programs runnable on a microcontroller. You will also need to rewrite OCaml’s runtime and develop a new GC for it.

~~In real life, no, you can’t run OCaml on a microcontroller. You need at least a couple of megabytes of normal RAM with MMU.~~ Well, see the next post, and this [paper](https://hal.sorbonne-universite.fr/hal-01705825/document).

---

<div class="post-metadata">

**Author:** ![ivg](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ivg/32/103_2.png) [@ivg](https://discuss.ocaml.org/u/ivg)\
**Post date:** [January 24, 2020, 7:07pm UTC](https://discuss.ocaml.org/t/ocaml-cross-compiler/1494/9 "2020-01-24T19:07:27Z")

</div>

Hmm, found this [project](https://github.com/stevenvar/OMicroB), that is also quite relevant to you, it is quite alive, so maybe you have chances 🙂
