tizoc / ocaml-interop

OCaml<->Rust FFI with an emphasis on safety.
MIT License
135 stars 22 forks source link

Linking error when running with `dune utop` #34

Open zshipko opened 3 years ago

zshipko commented 3 years ago

Here is the linker error when running dune utop in ocaml-rust-starter:

/usr/bin/ld: src/libocaml_rust_starter.a(ocaml_interop-4a398e80f3ca6ceb.ocaml_interop.8eq22uyz-cgu.12.rcgu.o): in function `_ZN3std4sync4once4Once9call_once28_$u7b$$u7b$closure$u7d$$u7d$17h7171c1b9a6fc7898E.llvm.3140953836603515050':
ocaml_interop.8eq22uyz-cgu.12:(.text._ZN3std4sync4once4Once9call_once28_$u7b$$u7b$closure$u7d$$u7d$17h7171c1b9a6fc7898E.llvm.3140953836603515050+0x3b): undefined reference to `caml_startup'
/usr/bin/ld: src/libocaml_rust_starter.a(ocaml_interop-4a398e80f3ca6ceb.ocaml_interop.8eq22uyz-cgu.12.rcgu.o): in function `_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h59471d095cabe6c5E.llvm.3140953836603515050':
ocaml_interop.8eq22uyz-cgu.12:(.text._ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h59471d095cabe6c5E.llvm.3140953836603515050+0x3b): undefined reference to `caml_startup'
collect2: error: ld returned 1 exit status

For more information: see the original issue

mrmr1993 commented 3 years ago

This is primarily an issue when compiling native libraries: you can't depend on caml_startup and friends being available if the library will later be linked against an OCaml program (or loaded dynamically, e.g. by dune utop) but is compiled separately first.

In the short term, I'm planning to remove the offending code in a local fork. Longer term, it would be great to see the runtime code as a separate library, and allow arbitrary code to 'claim' access to the OCaml runtime so that e.g. ocaml-rs can use the runtime when its functions are called from an existing runtime as well.

I'm happy to contribute to this effort, if useful.

tizoc commented 3 years ago

@mrmr1993 yes please! The only reason this has not been fixed is that no one has had time to do it, but a solution would be very welcome.

mrmr1993 commented 3 years ago

@tizoc done, see PR #36.