Need help for transitive linking of C libraries from their Rust sys crate wrappers

I intend to use Rust's FFI to call functions from a 3rd party C library. This C library's source and corresponding build artefacts have the following modular hierarchy:

└── intermediate
    └── base

Each library is to be compiled independently and linked up manually to obtain the corresponding hierarchy.

]There are cmake and make files distributed for each package, and I am able to manually compile and link the C libraries together as above.

Now, I wish to make use of the functionality of through Rust's FFI within Native Rust code. To this end, I have created three corresponding -sys packages, and used the package.links manifest in their Cargo.toml files, and passed the linker flags through the DEP_LIB_PROPERTY where property is an arbitrary key I have chosen (after reading the build script documentation).

Now, the problem is that I am able to compile the cargo workspace successfully, but the resulting libraries are broken. To explain, when compiled through Cargo, inspecting with ldd on confirms that it is correctly linked up to

However, ldd on reveals that, whilst it is correctly linked up to, rest of the linkage dependency is broken, i.e. does not get linked to resulting in a broken path.

How can I architect/confgure to achieve the desired effect of obtaining a properly linked transitive dependency tree?

You would need to inform the dynamic linker about the location of, either with an rpath in or with the LD_LIBRARY_PATH environment variable.

@sfackler Thank you for your response. I do not know much about these aspects. Could you please expand on "an rpath in"? How can I set this up in my build script for the intermediate-sys crate?

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.