Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot open library by its absolute path if it's not canonicalized #15

Open
fedochet opened this issue May 29, 2019 · 0 comments
Open

Comments

@fedochet
Copy link

fedochet commented May 29, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant