Get linked lib version during

I need to get the version for a library I'm linking from for a -sys crate. Is there a cross platform option for this built into Rust? Or do I need to use a per-system linker ecosystem to figure it out?

If that's not an option instead of linking to the lib's name directly in can I point to the lib file itself?

The -sys crate could set an env variable for you. The sys crate would print cargo:lib_version={} and you'd read it with env::var("DEP_FOO_LIB_VERSION").

Other than that I don't think there's any way, since Cargo doesn't even know exact paths that will be linked (only collects names and search dirs, and even that isn't exposed to build scripts).

1 Like