Linker errors when running Cargo test

I have created a rust lib (lib.rs), that uses and links c++ code.

Also have another rust app (main.rs) that uses this rust lib.
Note: I have added a build.rs file like to the rust main app,

build.rs

fn main() {
if cfg!(target_os = "linux"){
//required for aws green grass component -s2n
println!("cargo:rustc-link-search=/lib/x86_64-linux-gnu");
println!("cargo:rustc-link-search=/usr/lib/x86_64-linux-gnu");
println!("cargo:rustc-link-lib=dylib=crypto");
}
}

Doing a cargo build and/or cargo test against this rust app works fine.

However, when i try to run cargo test against the rust library, it fails with linker errors. ( cargo build works fine though)

Note :
I have added the same build.rs file(as used in rust main app) in the rust library too. But no luck , same issue.
Apparamtly, "cargo test" is loading build flags from elsewhere, not sure.

Any help is appreciated.