# Compiling ocaml dune project dynamically with 3rd party code

**URL:** <https://discuss.ocaml.org/t/compiling-ocaml-dune-project-dynamically-with-3rd-party-code/15589>\
**Category:** Learning\
**Tags:** opam, build, dune\
**Created:** [November 10, 2024, 7:58pm UTC](https://discuss.ocaml.org/t/compiling-ocaml-dune-project-dynamically-with-3rd-party-code/15589 "2024-11-10T19:58:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meir\_Tolpin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/meir_tolpin/32/5627_2.png) [@Meir\_Tolpin](https://discuss.ocaml.org/u/Meir_Tolpin)\
**Post date:** [November 10, 2024, 7:58pm UTC](https://discuss.ocaml.org/t/compiling-ocaml-dune-project-dynamically-with-3rd-party-code/15589/1 "2024-11-10T19:58:50Z")

</div>

Hello,

I am writing a project that is using another ocaml project (let’s say [GitHub - mirleft/ocaml-tls: TLS in pure OCaml](https://github.com/mirleft/ocaml-tls)).

I am able to compile my code, but looks like it is compiled statically. And from what I understand - usually ocaml is compiled statically (to another ocaml).

What I want is -

1. compiling the 3rd party project to some shared library
2. compiling my code dynamically so I will be able to change the implementation of the 3rd party code without recompiling my binary.

I am new to ocaml and after few hours of tries I still have no idea what should I search for.

Can someone please help me figuring out how can I find the relevant information for what I described above? Maybe some known project that does it or a dune file example

Thank you!

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [November 10, 2024, 8:45pm UTC](https://discuss.ocaml.org/t/compiling-ocaml-dune-project-dynamically-with-3rd-party-code/15589/2 "2024-11-10T20:45:00Z")

</div>

One search keyword would be “plugins” – in the sense of [ocaml\_plugin · OCaml Package](https://v3.ocaml.org/p/ocaml_plugin/latest) – although that’s a very general solution so maybe there are less heavy-weight ones.

Edit: `ocaml_plugin` is a bad idea though because it is meant for from-source dynamic loading. The underlying [`Dynlink`](https://ocaml.org/manual/5.2/api/Dynlink.html) works with `.cmxs` files, not sure how hard it would be to integrate with e.g. Dune-level packages, but probably not so easy.
