Linker errors when running Cargo test

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

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

fn main() {
if cfg!(target_os = "linux"){
//required for aws green grass component -s2n

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 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.