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:

top
└── intermediate
    └── base

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

top.so
└── intermediate.so
    └── base.so

]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 top.so 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 intermedite.so confirms that it is correctly linked up to base.so.

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

top.so
└── intermediate.so
     x 
     x
    └── base.so

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 base.so, either with an rpath in intermediate.so 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 intermediate.so"? 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.