The stubs library is found, but the underlying libgccjit.so library is not loaded. I tried various things like: adding -linkall; setting the env variables DYLD_LIBRARY_PATH, LD_LIBRARY_PATH, CAML_LD_LIBRARY_PATH; using byte_complete (doesn’t produce a .bc target); adding (ocamlc_flags (-custom)) (breaks the build).
I’m not familiar with Ctypes, so don’t have much to offer. But it is often useful to look at the link flags recorded in libgccjit.cma/libgccjit.cmxa, which you can do with eg ocamlobjinfo libgccjit.cma. I think you would like to see at least -lgccjit and -lgccjit_stubs (in that order). If -lgccjit is missing then it means that some link-time flag is not being passed correctly somewhere.
Yes, -lgccjit is neither in Extra dynamically-loaded libraries:, nor in the result of ldd build/_default/lib/dllgccjit_stubs.so. All flags are crammed into Extra C object files:.
Is it possible the lib is loaded but the symbol is stripped? I encountered this recently. The fix was -Wl,-export-dynamic (or -export_dynamic for mac).
I think you need to get -lgccjit inside the “Extra dynamically-loaded libraries” field of your archive. This is typically achieved by passing -lgccjit to the ocamlmklib invocation.
Thanks, I haven’t seen this in my searches! In the meantime, I had another idea to try: generate/vendor libgccjit.pc and use (build_flags_resolver pkg_config). If it doesn’t work, I’ll study this PR. Edit: ah, sorry I did see this. I linked this PR in my original post!
I now converted to (build_flags_resolver pkg_config), but the situation is the same: ocamlmklib still does not get any arguments (in particular it does not ask to link the external_library_name), and the execution still fails with the original error message.
Edit (updated): I now patched Add link flags ocamlmklib when using ctypes stubs. by frejsoya, and it solves the problem (both the (build_flags_resolver pkg_config) variant and the (build_flags_resolver (vendored ...)) variant). It still has the bytecode + c stubs not working as expected · Issue #108 problem when dune clean; dune exec – but it is easily solved by dune build; dune exec; alternatively need to update CAML_LD_LIBRARY_PATH i.e. dune clean; CAML_LD_LIBRARY_PATH=... dune exec works, but using (env (_ (env-vars (CAML_LD_LIBRARY_PATH ...)))) does not work.