Open mimoo opened 3 years ago
Also deps
should include any *.toml
file and Cargo.lock
files as well https://github.com/zshipko/ocaml-rust-starter/blob/master/src/dune#L3
Interestingly, things work on my mac without the "cdylib" here: https://github.com/zshipko/ocaml-rust-starter/blob/master/Cargo.toml#L8 but don't work with it
Thanks for the report!
The docs says you should add some flags to Cargo.toml on MacOS:
That is actually in .cargo/config
and is still needed on MacOS as far as I know
Second, why the C flags here? https://github.com/zshipko/ocaml-rust-starter/blob/master/src/dune#L17
These are needed on linux
Also deps should include any *.toml file and Cargo.lock
I'm happy to review a PR with that update
Interestingly, things work on my mac without the "cdylib" here: https://github.com/zshipko/ocaml-rust-starter/blob/master /Cargo.toml#L8 but don't work with it
What things don't work? Can you please provide a little more information or an error message?
here's the error I get when I try to compile with cdylib:
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-m64" "-arch" "x86_64" "-L" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.0.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.1.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.10.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.11.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.12.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.13.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.14.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.15.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.2.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.3.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.4.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.5.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.6.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.7.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.8.rcgu.o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.dalek_wrapper.34rx83c2-cgu.9.rcgu.o" "-o" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libdalek_wrapper.dylib" "-Wl,-exported_symbols_list,/var/folders/lw/r2z4bdmx0zv6gwb4vfgd36jm0000gn/T/builda03933.dune/rustcucLobo/list" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/dalek_wrapper.2m4gvxiqfmmmm1qx.rcgu.o" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs" "-L" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps" "-L" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/build/ocaml-boxroot-sys-6dbb819d7e7c3cb8/out" "-L" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/build/ocaml-boxroot-sys-6dbb819d7e7c3cb8/out" "-L" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libocaml-51e22a2035e14636.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libocaml_sys-f6329ac03066cc8c.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libchlorine-8774adbd5555a6b4.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libocaml_interop-07099bb348900dff.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libstatic_assertions-195add22e4ac19ca.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libocaml_sys-2aae64267d88dab5.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libcty-987d8b1c880d985f.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libocaml_boxroot_sys-a5747fe1e49eae55.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libx25519_dalek-80b9a7533c873446.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libcurve25519_dalek-6e81135c5cd8ab5a.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libsubtle-1787e0e3d3175d49.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libzeroize-90912ea98e896660.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libdigest-05ae0d8ad9bdb5a9.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libgeneric_array-7965c2c6fff536f8.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libtypenum-54f724f706b6fdc7.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libbyteorder-e9791942e46f5d98.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/librand-345b937d38afb532.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/librand_chacha-e8c02286d9ca6862.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libppv_lite86-eae860cdfe3edba4.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/librand_core-e07aa152a7cc8393.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libgetrandom-8e6206411887599e.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/liblibc-9f246602cd5bdf6f.rlib" "/Users/davidwong/Perso/dalek-ocaml/_build/default/x25519/dalek-wrapper/target/release/deps/libcfg_if-ab0a1d7042ede875.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-9225b8e469c32698.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-2fe2b8cd4fa63c34.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-80083cf4ee7ee3ff.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-ddf3832e718029e6.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-ba92c986e8ef2ca8.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-acd0bd456d8da820.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-55608c4156e4ecbb.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-4be618026614fdc7.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-fee25922260aa100.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-38ba3c5cc408e14d.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-899852a009fbe35f.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-5687564a0ccea916.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-9ed2c58b16cff4ee.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-244bf5611f93ff45.rlib" "/Users/davidwong/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-70df686e6b4ebf5b.rlib" "-lc" "-lm" "-liconv" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv"
= note: Undefined symbols for architecture x86_64:
"_caml_scan_roots_hook", referenced from:
_boxroot_setup in libocaml_boxroot_sys-a5747fe1e49eae55.rlib(boxroot.o)
_boxroot_teardown in libocaml_boxroot_sys-a5747fe1e49eae55.rlib(boxroot.o)
"_caml_minor_gc_end_hook", referenced from:
_boxroot_setup in libocaml_boxroot_sys-a5747fe1e49eae55.rlib(boxroot.o)
_boxroot_teardown in libocaml_boxroot_sys-a5747fe1e49eae55.rlib(boxroot.o)
"_Caml_state", referenced from:
_boxroot_create in libocaml_boxroot_sys-a5747fe1e49eae55.rlib(boxroot.o)
"_caml_alloc", referenced from:
ocaml::value::Value::alloc::h7985cee03af55bc2 in libocaml-51e22a2035e14636.rlib(ocaml-51e22a2035e14636.ocaml.3lwj6a2r-cgu.0.rcgu.o)
"_caml_raise_with_arg", referenced from:
ocaml::error::Error::raise_value::h89987d2ae2218392 in libocaml-51e22a2035e14636.rlib(ocaml-51e22a2035e14636.ocaml.3lwj6a2r-cgu.1.rcgu.o)
"_caml_alloc_string", referenced from:
ocaml::error::Error::raise_failure::hcddab59271631890 in libocaml-51e22a2035e14636.rlib(ocaml-51e22a2035e14636.ocaml.3lwj6a2r-cgu.1.rcgu.o)
ocaml::error::Error::raise_value::h89987d2ae2218392 in libocaml-51e22a2035e14636.rlib(ocaml-51e22a2035e14636.ocaml.3lwj6a2r-cgu.1.rcgu.o)
"_caml_minor_gc_begin_hook", referenced from:
_boxroot_setup in libocaml_boxroot_sys-a5747fe1e49eae55.rlib(boxroot.o)
_boxroot_teardown in libocaml_boxroot_sys-a5747fe1e49eae55.rlib(boxroot.o)
"_caml_modify", referenced from:
ocaml_sys::memory::store_field::h58d85e38bf0612a5 in libocaml_sys-f6329ac03066cc8c.rlib(ocaml_sys-f6329ac03066cc8c.ocaml_sys.3z8xms3n-cgu.9.rcgu.o)
"_caml_failwith_value", referenced from:
ocaml::error::Error::raise_failure::hcddab59271631890 in libocaml-51e22a2035e14636.rlib(ocaml-51e22a2035e14636.ocaml.3lwj6a2r-cgu.1.rcgu.o)
"_caml_named_value", referenced from:
ocaml::value::Value::named::h1d8d114e5c18f297 in libocaml-51e22a2035e14636.rlib(ocaml-51e22a2035e14636.ocaml.3lwj6a2r-cgu.0.rcgu.o)
"_caml_array_length", referenced from:
ocaml::conv::_$LT$impl$u20$ocaml..value..FromValue$u20$for$u20$alloc..vec..Vec$LT$V$GT$$GT$::from_value::h800f76b6842f69dc in dalek_wrapper.dalek_wrapper.34rx83c2-cgu.2.rcgu.o
"_caml_alloc_custom", referenced from:
_to_public_key in dalek_wrapper.dalek_wrapper.34rx83c2-cgu.0.rcgu.o
_public_from_bytes in dalek_wrapper.dalek_wrapper.34rx83c2-cgu.0.rcgu.o
ocaml::types::Pointer$LT$T$GT$::alloc_custom::h543cdae9d1a1d761 in dalek_wrapper.dalek_wrapper.34rx83c2-cgu.4.rcgu.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've found that using the following in a build.rs
(in same directory as Cargo.toml
):
fn main() {
if cfg!(any(target_os = "macos", target_os = "ios")) {
println!("cargo:rustc-link-arg=-Wl,-undefined,dynamic_lookup");
}
}
works well as long as you have https://github.com/rust-lang/cargo/pull/9557 (Rust 1.56.0).
(I'm added iOS since I suspect it has the same problem)
The docs says you should add some flags to
Cargo.toml
on MacOS:yet we don't do it here: https://github.com/zshipko/ocaml-rust-starter/blob/master/Cargo.toml
yet (bis) it works fine on my mac without these build flags.
Second, why the C flags here? https://github.com/zshipko/ocaml-rust-starter/blob/master/src/dune#L17
It works fine on my mac without these :o