From 243e9c8339677041af2051cab78e151cbbdbeb75 Mon Sep 17 00:00:00 2001 From: Bet4 <0xbet4@gmail.com> Date: Thu, 2 Mar 2023 03:34:33 +0800 Subject: [PATCH] Fix dynamic linkage on msvc --- bindings/rust/build.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs index 04f5431a..821367d3 100644 --- a/bindings/rust/build.rs +++ b/bindings/rust/build.rs @@ -138,7 +138,11 @@ fn build_with_cmake() { // Lazymio(@wtdcode): Dynamic link may break. See: https://github.com/rust-lang/cargo/issues/5077 if cfg!(feature = "dynamic_linkage") { - println!("cargo:rustc-link-lib=dylib=unicorn"); + if compiler.is_like_msvc() { + println!("cargo:rustc-link-lib=dylib=unicorn-import"); + } else { + println!("cargo:rustc-link-lib=dylib=unicorn"); + } } else { println!("cargo:rustc-link-lib=static=unicorn"); } @@ -159,7 +163,11 @@ fn main() { println!("cargo:rustc-link-search=native={}", dir.to_str().unwrap()); } if cfg!(feature = "dynamic_linkage") { - println!("cargo:rustc-link-lib=dylib=unicorn"); + if cc::Build::new().get_compiler().is_like_msvc() { + println!("cargo:rustc-link-lib=dylib=unicorn-import"); + } else { + println!("cargo:rustc-link-lib=dylib=unicorn"); + } } else { println!("cargo:rustc-link-arg=-Wl,-allow-multiple-definition"); println!("cargo:rustc-link-lib=static=unicorn");