Plugin loading when executing without dune

Hi there,
I followed the tutorial How to Load Additional Files at Runtime — Dune documentation to dynload plugins with dune. Everything work well.
However, when I want to execute app.exe without dune with the command

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

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?

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

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

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

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

1 Like

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

1 Like

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.