Check the presence of a library required by bindings

Hi,

I am not sure this question has anything to do with Rust, but who knows? If the library required by the bindings is not present on the system, is there a way to check it and provide a meaningful message before the app fails?

Libraries are usually statically linked in Rust. In case you are linking to a dll, the loader of OS will simply fail to load the binary.

If you want to do something like LoadLibrary/GetProcAddress, I would suggest you to look into libloading, you can check that all functions were loaded successfully. The downside is, the functions won't be available globally and code will require unsafe blocks.

I'm talking about bindings. Which implies an external library which may or may not be present on the system. Is there a clean way to check its presence?

No, because the loader will require the library to be present at load time.

This is something *-sys crates tend to do quite often during the compilation process. In a build.rs script it'll check if a desired library is available on the system and tell rustc to link to that, otherwise it'll fall back to compiling the library from source.

Some examples:

1 Like

Yes, you can. I even encourage to bundle library's source and build it if it's not installed.

https://kornel.ski/rust-sys-crate