nagisa / rust_libloading

Bindings around the platform's dynamic library loading primitives with greatly improved memory safety.
https://docs.rs/libloading
ISC License
1.24k stars 102 forks source link

Relative path doesn't seem to work on Linux #124

Closed ShayBox closed 1 year ago

ShayBox commented 1 year ago

Using a relative path doesn't seem to work on Linux, but it does on Windows

Broken:
https://github.com/ShayBox/VRC-OSC/blob/e8d81c9fc95e0ac1c9c7c036bc445ba8e95b097c/loader/src/lib.rs#L40

Fixed:
https://github.com/ShayBox/VRC-OSC/blob/015acd1f835545dfdce1ee95646d874ea2e60346/loader/src/lib.rs#L63-L68

nagisa commented 1 year ago

Where the dynamic libraries are searched for is dependent on the host system and is specific to it. This is documented in the libloading’s documentation.

ShayBox commented 1 year ago

Right, I didn't see the last paragraph of the tips section

The last example shows example.so which in all other cases (even pkg-config) is relative to cwd, but libloading requires an explicit ./ to be relative, otherwise it only searches globally on Linux (and possibly macOS)

nagisa commented 1 year ago

Reading the description of how libraries are searched by dlopen may help. In particular note that none of the steps involve searching a path relative to the binary like it is on Windows. If you would like that you might want to set the binary’s RPATH to include $ORIGIN. Then dlopen as a very first couple steps will look around the directory in which the binary is located.