Ocaml cross compiler?

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?


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.

The docs about how to use it is already live, but I’m still not really sure how it works.

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.


I’m still not sure how to do this…

Have there been new developments on this front?


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”.

1 Like

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

You may find this page 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.

1 Like

Hmm, found this project, that is also quite relevant to you, it is quite alive, so maybe you have chances :slight_smile:

1 Like