Linker 锈罐';t链接到C库的绑定

Linker 锈罐';t链接到C库的绑定,linker,rust,ffi,Linker,Rust,Ffi,我按照教程为其进行绑定。由于链接错误,我无法运行测试: /home/user/project/rust-scrypt/src/lib.rs:32:crypto\u-scrypt的未定义引用 collect2:错误:ld返回了1个退出状态 还有我的测试: include!(concat!(env!("OUT_DIR"), "/bindings.rs")); // ... // ... #[test] fn test_script() { let mut kdf_salt = to_bytes

我按照教程为其进行绑定。由于链接错误,我无法运行测试:

/home/user/project/rust-scrypt/src/lib.rs:32:crypto\u-scrypt的未定义引用
collect2:错误:ld返回了1个退出状态
还有我的测试:

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
// ...
// ...
#[test]
fn test_script() {
  let mut kdf_salt = to_bytes("fd4acb81182a2c8fa959d180967b374277f2ccf2f7f401cb08d042cc785464b4");
    let passwd = "1234567890";
    let mut buf = [0u8; 32];

    unsafe {
        crypto_scrypt(passwd.as_ptr(), passwd.len(), kdf_salt.as_mut_ptr(), kdf_salt.len(),
                      2, 8, 1, buf.as_mut_ptr(), 32);
    }

    println!(">> DEBUG: {:?}", buf);
    // "52a5dacfcf80e5111d2c7fbed177113a1b48a882b066a017f2c856086680fac7");
}
绑定已生成并存在于
bindings.rs
中。我不知道链接器为什么会抛出错误

这是我的

还有我的


请重新熟悉一下。具体地说,您已经通知了Rust库的接口是什么,但还没有告诉编译器代码在哪里。这就是您遇到的错误:“我找不到
crypto\u-scrypt
的实现。”

您需要将库添加到链接器路径,并指示它根据链接器路径进行链接

从链接的案例研究中,构建脚本可以通知编译器库的位置以及链接的对象:

println!("cargo:rustc-link-search=native={}", path_to_library);
println!("cargo:rustc-link-lib=static=hello"); // the name of the library
请,请,请阅读关于此类集成最佳实践的文档部分。也就是说,您的Cargo.toml缺少,如果有人多次尝试链接此库,这将导致问题

--


请注意,已经有了。

当您使用时,请包括该库的版本(您是根据主分支构建它的吗)?是的,使用masterI从
rust crypto
迁移,因为他要慢,大约比同一算法的Go实现慢100倍。其他板条箱基于锈迹加密或不够成熟。我已经花了一些时间调查这件事了)
[package]
name = "rust-scrypt"
version = "0.0.1"
build = "build.rs"

[build-dependencies]
bindgen = "0.23"
println!("cargo:rustc-link-search=native={}", path_to_library);
println!("cargo:rustc-link-lib=static=hello"); // the name of the library