Git Product home page Git Product logo

Comments (7)

hansihe avatar hansihe commented on May 19, 2024

This looks like rusterlium/erlang_nif-sys#3.

Try adding

#![feature(link_args)]
#[link_args = "-flat_namespace -undefined suppress"]
extern {}

to the top of the nif.rs file.

from rustler.

developerworks avatar developerworks commented on May 19, 2024

Add add above feature code at top of lib.rs like this:

#![feature(link_args)]
#[link_args = "-flat_namespace -undefined suppress"]
extern {}
#![feature(plugin)]
#![plugin(rustler_codegen)]

#[macro_use]
extern crate rustler;
use rustler::{NifEnv, NifTerm, NifError, NifDecoder, NifEncoder};
use rustler::resource::ResourceCell;

rustler_export_nifs!(
    "Elixir.NativeTest",
    [("add", 2, add),
     ("panic_test", 0, panic_test),
     ("struct_argument", 1, struct_argument),
     ("make_resource_struct", 0, make_resource_struct),
     ("read_resource_struct", 1, read_resource_struct),
     ("string_test", 0, string_test)],
    Some(on_load)
);

but the errors raised:

➜  native git:(master) cargo build
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling libc v0.2.11
   Compiling aster v0.16.0
   Compiling lazy_static v0.1.16
   Compiling easy-plugin v0.3.4
   Compiling ruster_unsafe v0.4.0
   Compiling rustler v0.8.3 (file:///Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler)
/Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/src/codegen_runtime.rs:8:5: 8:24 warning: use of deprecated item: renamed to `catch_unwind`, #[warn(deprecated)] on by default
/Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/src/codegen_runtime.rs:8 use std::panic::recover;
                                                                                     ^~~~~~~~~~~~~~~~~~~
/Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/src/codegen_runtime.rs:23:51: 23:58 warning: use of deprecated item: renamed to `catch_unwind`, #[warn(deprecated)] on by default
/Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/src/codegen_runtime.rs:23     let result: ::std::thread::Result<NIF_TERM> = recover(|| {
                                                                                                                                    ^~~~~~~
   Compiling rustler_codegen v0.8.3 (file:///Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/rustler_codegen)
/Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/rustler_codegen/src/resource.rs:66:13: 66:20 warning: unused variable: `builder`, #[warn(unused_variables)] on by default
/Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/rustler_codegen/src/resource.rs:66         let builder = ::aster::AstBuilder::new().span(span);
                                                                                                       ^~~~~~~
/Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/rustler_codegen/src/resource.rs:66:13: 66:20 note: in this expansion of easy_plugin! (defined in /Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler/rustler_codegen/src/lib.rs)
   Compiling native v0.1.0 (file:///Users/hezhiqiang/RustProjects/rustler_issue_16/Rustler_Example/native)
src/lib.rs:4:3: 4:4 error: an inner attribute is not permitted in this context
src/lib.rs:4 #![feature(plugin)]
               ^
src/lib.rs:4:3: 4:4 help: place inner attribute at the top of the module or block
src/lib.rs:5:3: 5:4 error: an inner attribute is not permitted in this context
src/lib.rs:5 #![plugin(rustler_codegen)]
               ^
src/lib.rs:5:3: 5:4 help: place inner attribute at the top of the module or block
src/lib.rs:36:5: 36:25 error: macro undefined: 'resource_struct_init!'
src/lib.rs:36     resource_struct_init!(ResourceStructTest, env);
                  ^~~~~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors
error: Could not compile `native`.

To learn more, run the command again with --verbose.

my rust version is:

➜  native git:(master) ✗ rustc --version
rustc 1.10.0-nightly (62e2b2fb7 2016-05-06)

from rustler.

developerworks avatar developerworks commented on May 19, 2024

It's fix by adjust the order with:

#![feature(plugin)]
#![plugin(rustler_codegen)]
#![feature(link_args)]
#[link_args = "-flat_namespace -undefined suppress"]
extern {}

#[macro_use]
...
...
...

from rustler.

developerworks avatar developerworks commented on May 19, 2024

But, it's seems like nif load path is mistake on osx:

➜  Rustler_Example git:(master) ✗ elixir run.exs 
run.exs:34: warning: variable res is unused
** (MatchError) no match of right hand side value: {:error, :on_load_failure}
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6


20:05:11.297 [error] Process #PID<0.55.0> raised an exception
** (MatchError) no match of right hand side value: {:error, {:load_failed, 'Failed to load NIF library: \'dlopen(native/target/debug/librust_nif.so, 2): image not found\''}}
    run.exs:12: NativeTest.init/0
    (kernel) code_server.erl:1669: anonymous fn/1 in :code_server.handle_on_load/4

20:05:11.301 [warn]  The on_load function for module Elixir.NativeTest returned {{:badmatch,
  {:error,
   {:load_failed,
    'Failed to load NIF library: \'dlopen(native/target/debug/librust_nif.so, 2): image not found\''}}},
 [{NativeTest, :init, 0, [file: 'run.exs', line: 12]},
  {:code_server, :"-handle_on_load/4-fun-0-", 1,
   [file: 'code_server.erl', line: 1669]}]}


from rustler.

developerworks avatar developerworks commented on May 19, 2024

Fixed with:

cp ./native/target/debug/librust_nif.dylib to ./native/target/debug/librust_nif.so

or

ln -s ./native/target/debug/librust_nif.dylib ./native/target/debug/librust_nif.so

from rustler.

brendanzab avatar brendanzab commented on May 19, 2024

This seems quite similar to #12!

from rustler.

hansihe avatar hansihe commented on May 19, 2024

Yep, both problems where the same.

from rustler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.