Search code examples
ocamlreasonocaml-dune

Ocaml / ReasonML - Missing libraries in built executable


I have an ReasonML project that is using dune build to build an executable. The executable runs on the development machine (where the code is built) without any problems. However, if I copy this exe to my other laptop (Another mac with the same OSX version), I can´t execute the file due to missing libraries:

dyld: Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib
  Referenced from: /usr/local/bin/foo
  Reason: image not found

I´m not very experienced with ocaml / reason but I expected the executable to bundle all necessary dependencies within the binary.

Is there a special build-flag or some other step that I have to perform apart from dune build in order to include all necessary libs?


Solution

  • What you are looking for is statically linking binaries. MacOS unfortunately does not official encourage or recommend static linking. An old page can be found here. You might find this Stackoverflow answer useful as well.

    This has less to do with OCaml itself and more wrt how linkers behave on different platforms (MacOS, Linux etc)

    To overcome your issue, you could checkout esy-gmp assuming you are using esy as your package manager. If you're on OPAM, you could add conf-gmp to you opam dependencies

    All this being said, if you're interested in static linking on supported platform like Linux (and Windows too I guess?), you'll have to provide C linker flags via dune

    (link_flags (-ccopt -static))