danielpclark / rutie

“The Tie Between Ruby and Rust.”
MIT License
940 stars 62 forks source link

Example code in README leads to linking errors #137

Closed amw-zero closed 3 years ago

amw-zero commented 3 years ago

Following the example code in the README for calling Rust from Ruby led to the following error for me:

alex.weisberger@hq-mbp-alexweisberger rutie_ruby_example % cargo build
   Compiling libc v0.2.80
   Compiling rutie v0.8.1
   Compiling lazy_static v1.4.0
   Compiling rutie_ruby_example v0.1.0 (/Users/alex.weisberger/code/rutie_ruby_example)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-arch" "x86_64" "-L" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.11q727vvefaevrgc.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.12cmroqxm1v6w82i.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.13rwlaby184m84vu.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.1inmyugmpz48gsd1.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.1le1raml7q98jvdx.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.1y4acf0zfcbs193n.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.34ma6hgf2pohzwr4.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.3cltky4kxueandzf.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.3fvje93866ikqr6o.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.3ifmhzeog215p5ng.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.3sqem6ck3s4rkxfg.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.3tzohvolf7wfsroj.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.3wu9kx8o1vy55jof.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.3yhtwtbzcg5qzek0.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.442z675k1qo8low2.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.44damv685dvi8uo6.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.4dtvikikt94104vo.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.4eqi3u60emg32hnp.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.4hqid910kt6voa39.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.4jicv1x3i5o4al25.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.4q8gysy1ka9xuw3d.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.4vpxglhiqgzykwxq.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.4y18zc35i7o069rs.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.50m2zi5k0c0ch31d.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.52etfccwdi2wjkz8.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.54v3bj03n3nz389k.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.57evdjplmp36t4dy.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.5baxxzbe43evixiw.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.5dup4iu6xeglpp8t.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.8fbg87d4431ni44.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.dv749jpiy2zqbg0.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.jhx1fqu7uhg6yh0.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.jvje28rhvoyghqp.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.s83947a79u7r8f6.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.sfmslqr8z0ax1qs.rcgu.o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.z2lm3cwj17cwxp6.rcgu.o" "-o" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/librutie_ruby_example.dylib" "-Wl,-exported_symbols_list,/var/folders/_j/lj_s009n4bn2q2x3y3k5ntpm0000gp/T/rustcdXmJbY/list" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/rutie_ruby_example.55by2lg2xogu0bs.rcgu.o" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs" "-L" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps" "-L" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/librutie-fcf5b68285cb8bee.rlib" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/liblibc-67370c729c9509e9.rlib" "/Users/alex.weisberger/code/rutie_ruby_example/target/debug/deps/liblazy_static-b4401f02f4fbcaf3.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-688c1376a25c049d.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-078f89c2cdb6d46b.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-fec020208bc1ad3c.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-38540dcacc9fd218.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-6f613179f618c598.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-4d1a5d7118aaeaf2.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-d88fab3b1b9d8356.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-a21754532a052f2f.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-2e9ebc4127641a96.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-82d0f961232a05ca.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-370b1b71f08bac3c.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-816106c1f35f5421.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-20f3a030f1a56a86.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-60333aa00936c5ce.rlib" "/Users/alex.weisberger/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-116aaeaea873ef94.rlib" "-lSystem" "-lresolv" "-lc" "-lm"
  = note: Undefined symbols for architecture x86_64:
            "_rb_define_class", referenced from:
                rutie::binding::class::define_class::h7b8247193a3fa385 in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.10.rcgu.o)
            "_rb_funcallv", referenced from:
                rutie::binding::vm::call_method::hbd76d6098d2488cf in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.14.rcgu.o)
            "_rb_string_value_cstr", referenced from:
                rutie::binding::string::value_to_string::h2f04d887b782c46e in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.13.rcgu.o)
            "_rb_utf8_str_new", referenced from:
                rutie::binding::string::new_utf8::he32cd2db6829b590 in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.13.rcgu.o)
            "_rb_intern2", referenced from:
                rutie::binding::symbol::internal_id::h4f486e6fa3135f71 in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.6.rcgu.o)
            "_rb_cObject", referenced from:
                rutie::class::class::Class::superclass_to_value::hfcbfcf1309bdc603 in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.9.rcgu.o)
                rutie::util::inmost_rb_object::h9f13d555f3b3b34b in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.15.rcgu.o)
            "_rb_const_get", referenced from:
                rutie::binding::class::const_get::h75c9cdd8fbebeb9b in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.10.rcgu.o)
            "_rb_exc_raise", referenced from:
                rutie::binding::vm::raise_ex::h621857d0bff6ffb1 in librutie-fcf5b68285cb8bee.rlib(rutie-fcf5b68285cb8bee.rutie.cpab5xen-cgu.14.rcgu.o)
            "_rb_define_singleton_method", referenced from:
                rutie::binding::class::define_singleton_method::hc64422c5f9698d77 in rutie_ruby_example.4q8gysy1ka9xuw3d.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)

error: aborting due to previous error

error: could not compile `rutie_ruby_example`

MacOS version 10.15.7 Rutie version 0.8.1 Ruby version 2.7.2 (compiled with --enable-shared). rustc version 1.48.0

This error means that the Rust --> Ruby bindings have not linked (i.e. here) the Ruby C library.

I noticed that the example app in the repo does not specify the no-link cargo feature, and removing that feature from my example app allowed rutie to compile.

amw-zero commented 3 years ago

I have a PR for the removal of no-link from the example app code's Cargo.toml here: https://github.com/danielpclark/rutie/pull/136

amw-zero commented 3 years ago

cc @danielpclark

danielpclark commented 3 years ago

Thanks for tagging me in this.

amw-zero commented 3 years ago

I’ve opened issues before where the maintainer did not get a notification automatically. Hopefully that didn’t come off as pushy, and if it did I apologize.

danielpclark commented 3 years ago

Not pushy at all. I don't get notifications unless I'm tagged or following something. It was, and is, a sincere thanks.

danielpclark commented 3 years ago

@amw-zero Just out of curiosity what OS are you using?

amw-zero commented 3 years ago

This happened to me on MacOS version 10.15.7.

danielpclark commented 3 years ago

@amw-zero Can you try it with Rutie v0.8.2 ? The build script previously had issues if rutie is included with a relative path. I don't know if that's how you were including it.

I have made it so that the no-link option is not on by default as I believe it was causing more problems for users than it was helping... but the option is still there. If this is no longer an issue please feel free to close the issue.