From 52ff133528dbd3e5baa3980ce10ea10d5005fbe0 Mon Sep 17 00:00:00 2001 From: taks <857tn859@gmail.com> Date: Wed, 31 Jul 2024 10:18:51 +0900 Subject: [PATCH] Prioritize loading dll in the directory containing libclang.dll on Windows (#187) --- src/link.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/link.rs b/src/link.rs index 87f94ba60..22253fe4b 100644 --- a/src/link.rs +++ b/src/link.rs @@ -235,7 +235,19 @@ https://rust-lang.github.io/rust-bindgen/requirements.html let path = directory.join(filename); unsafe { - let library = libloading::Library::new(&path).map_err(|e| { + #[cfg(target_os = "windows")] + // Prioritize loading dll in the directory containing libclang.dll + let library = + libloading::os::windows::Library::load_with_flags( + &path, + libloading::os::windows::LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | + libloading::os::windows::LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR) + .map(From::from); + + #[cfg(not(target_os = "windows"))] + let library = libloading::Library::new(&path); + + let library = library.map_err(|e| { format!( "the `libclang` shared library at {} could not be opened: {}", path.display(),