# Plugin loading when executing without dune

**URL:** <https://discuss.ocaml.org/t/plugin-loading-when-executing-without-dune/15440>\
**Category:** Learning\
**Tags:** dune\
**Created:** [October 14, 2024, 3:03pm UTC](https://discuss.ocaml.org/t/plugin-loading-when-executing-without-dune/15440 "2024-10-14T15:03:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![intermet](https://avatars.discourse-cdn.com/v4/letter/i/85f322/32.png) [@intermet](https://discuss.ocaml.org/u/intermet)\
**Post date:** [October 14, 2024, 3:03pm UTC](https://discuss.ocaml.org/t/plugin-loading-when-executing-without-dune/15440/1 "2024-10-14T15:03:00Z")

</div>

Hi there,  
I followed the tutorial [How to Load Additional Files at Runtime — Dune documentation](https://dune.readthedocs.io/en/stable/sites.html#plugins) to dynload plugins with dune. Everything work well.  
However, when I want to execute `app.exe` without dune with the command

```auto
dune build @install && ./_build/install/default/bin/app

```

With this command, the plugin is not registered. Which supplementary steps are needed?  
When the package is installed on a system, shouldn’t we expect to run the binary without dune?

Thank you for your help

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [October 15, 2024, 7:50am UTC](https://discuss.ocaml.org/t/plugin-loading-when-executing-without-dune/15440/2 "2024-10-15T07:50:06Z")

</div>

Could it have to do with file name resolution? In your main program you call `Dynlink.loadfile "somewhere"` with a location of a to-be-dynlinked compilation unit. It could happen easily that in your invocation “somewhere” does not point to the correct file?

---

<div class="post-metadata">

**Author:** ![intermet](https://avatars.discourse-cdn.com/v4/letter/i/85f322/32.png) [@intermet](https://discuss.ocaml.org/u/intermet)\
**Post date:** [October 15, 2024, 8:28am UTC](https://discuss.ocaml.org/t/plugin-loading-when-executing-without-dune/15440/3 "2024-10-15T08:28:59Z")

</div>

The thing is that I am not using the Dynlink module (see link). With the command

```auto
dune build @install && dune exec ./app.exe

```

the plugin is correctly loaded.  
I wonder what `dune exec` is actually doing under the hood.

---

<div class="post-metadata">

**Author:** ![reynir](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/reynir/32/6496_2.png) [@reynir](https://discuss.ocaml.org/u/reynir)\
**Post date:** [October 15, 2024, 9:15am UTC](https://discuss.ocaml.org/t/plugin-loading-when-executing-without-dune/15440/4 "2024-10-15T09:15:18Z")

</div>

For one `dune exec` modifies some environment variables, for example `$PATH`. You can compare the output of `env` vs `dune exec -- env`.

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [October 15, 2024, 11:07am UTC](https://discuss.ocaml.org/t/plugin-loading-when-executing-without-dune/15440/5 "2024-10-15T11:07:47Z")

</div>

I see. If I understand the dune-sites docs correctly, under the hood, `Dynlink.load_file` is actually called, and that call must reside in the generated sites module (‘sites.ml’ in the doc example).

You could try to fully install the package to see if it works then. I.e. let dune generate opam files and then opam-install your package into the current opam switch. I suspect this will produce a different situation than directly running the program from \_build/install

Also, trying building with `--verbose` may shed some light what is actually done by `dune build @install`

---

<div class="post-metadata">

**Author:** ![intermet](https://avatars.discourse-cdn.com/v4/letter/i/85f322/32.png) [@intermet](https://discuss.ocaml.org/u/intermet)\
**Post date:** [November 10, 2024, 2:21pm UTC](https://discuss.ocaml.org/t/plugin-loading-when-executing-without-dune/15440/6 "2024-11-10T14:21:35Z")

</div>

The issue came from the way my system install packages. I use guix and OCAMLPATH was not set correctly when installing the plugin package. I was able to fix it.
