I am facing strange behavior: when I am passing the absolute path to Lib::new method, it returns an error saying that it cannot find the file. However, calling canonicalize on the passed Path removes the problem. I wouldn't call it weird if the original path wouldn't be absolute, but it is
I've used this code to check if my suspicions are correct. I've used sharedlib and libloading crates as alternatives. The second test passes, and the first one fails on the third assert
use sharedlib::Lib;
use libloading::Library;
use std::path::Path;
static LIB_PATH: &str = "/tmp/libgetset.so";
#[test]
fn test_not_canonical_path() {
let path = Path::new(LIB_PATH);
println!("{:?}", &path);
assert!(path.exists());
let library = unsafe { Library::new(&path) };
assert!(library.is_ok());
let library = unsafe { Lib::new(&path) };
assert!(library.is_ok());
}
#[test]
fn test_canonical_path() {
let path = Path::new(LIB_PATH).canonicalize().unwrap();
println!("{:?}", &path);
assert!(path.exists());
let library = unsafe { Library::new(&path) };
assert!(library.is_ok());
let library = unsafe { Lib::new(&path) };
assert!(library.is_ok());
}
fn main() {
}
I am using Linux machine with Ubuntu 16.04
The dynamic library I am using is compiled getset procedural macro, but I think it doesn't really matter and you can replace it with what you have at hand
I am facing strange behavior: when I am passing the absolute path to
Lib::newmethod, it returns an error saying that it cannot find the file. However, callingcanonicalizeon the passedPathremoves the problem. I wouldn't call it weird if the original path wouldn't be absolute, but it isI've used this code to check if my suspicions are correct. I've used
sharedlibandlibloadingcrates as alternatives. The second test passes, and the first one fails on the third assertI am using Linux machine with Ubuntu 16.04
The dynamic library I am using is compiled
getsetprocedural macro, but I think it doesn't really matter and you can replace it with what you have at hand