ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.6k stars 396 forks source link

Dynamic loading of packages: linking issues #10697

Open Kakadu opened 2 months ago

Kakadu commented 2 months ago

Expected Behavior

I have a demo https://github.com/Kakadu/dune-sites-demo/tree/llvm where my plugin depends on LLVM and I want to load this plugin. It gives me an error undefined symbol: llvm_create_context.

I created an ocamlfind demo (in the repo, works) and it looks like it passes more cmxa command line arguments. I tried to do the same by manually

(cd _build/default && /media/work2/.opam/llvm16/bin/ocamlopt.opt -g -linkall -shared -linkall -I plugin -o plugin/plugin1_impl.cmxs plugin/plugin1_impl.cmxa -I /media/work2/.opam/llvm16/lib/llvm /media/work2/.opam/llvm16/lib/llvm/shared/llvm.cmxa -verbose  )

and after that it starts to give another error Dynlink.Uninitialized_global "Llvm". Any advice how to fix this? Do we need patching dune?

Reproduction

https://github.com/Kakadu/dune-sites-demo/tree/llvm

Specifications

dune 3.16

Kakadu commented 1 month ago

I discovered that the main app should explicitly depend on LLVM. https://github.com/ocaml/dune/blob/3.16.0/otherlibs/dune-site/test/plugin_require_thread.t/run.t Don't know why it is required...