Created
May 22, 2020 16:09
-
-
Save nviennot/b3a48b77e13aa5a23815529c7d34bd15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code)] | |
use std::path::PathBuf; | |
use std::env; | |
fn find_abs_lib_path(lib_name: &str) -> Result<PathBuf, &str> { | |
let mut search_paths = vec![]; | |
if let Some(ld_library_path) = env::var_os("LD_LIBRARY_PATH") { | |
search_paths.extend(env::split_paths(&ld_library_path)); | |
} | |
if let Some(path) = env::var_os("PATH") { | |
search_paths.extend(env::split_paths(&path)); | |
} | |
search_paths.extend(["/lib64", "/usr/lib"].iter().map(PathBuf::from)); | |
for base_path in search_paths { | |
let path = base_path.join(lib_name); | |
if path.exists() { | |
return Ok(path); | |
} | |
} | |
Err("Failed to find lib") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment