How to fix: error: linking with `cc` failed: exit status: 1

Hi again !

I faced with another issue, which is related to prev topic. When I compile c++ lib using cmake crate, I got this error:

error: linking with `cc` failed: exit status: 1
  = note: /usr/bin/ld: cannot find -lsrp6: No such file or directory
          collect2: error: ld returned 1 exit status

This is the updated repo to reproduce: GitHub - sergio-ivanuzzo/reproduce-cpp-to-rust

I tried to use srp6 instead of libsrp6 here:

// build.rs
fn main() {
    let dst = cmake::Config::new("libsrp6").build();

    // libsrp6 was replaced below with srp6
    println!("cargo:rustc-link-lib=dylib=libsrp6");
    // ...
}

and here:

extern "C" {
    // libsrp6 was replaced below with srp6
    #[link(name="libsrp6", kind="dylib")]
    fn test_srp6(
        N_str: *const c_char,
        g_str: *const c_char,
        B_str: *const c_char,
        s_str: *const c_char,
        username_str: *const c_char,
        password_str: *const c_char
    );
}

but error is same. Nothing changed.

Could somebody help me to fix the issue ?

I found the solution. I should add this line to my build.rs:

println!("cargo:rustc-link-search=libsrp6");

so the final build.rs looks like this:

fn main() {
    let dst = cmake::build("libsrp6");

    println!("cargo:rustc-link-search=native={}", dst.display());
    println!("cargo:rustc-link-search=libsrp6");
    println!("cargo:rustc-link-lib=dylib=srp6");
    println!("cargo:rustc-link-lib=dylib=ssl");
    println!("cargo:rustc-link-lib=dylib=crypto");
    println!("cargo:rustc-link-lib=dylib=stdc++");
}

this compiles with no errors. Thanks to all.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.