Skip to content

Commit

Permalink
Merge pull request #1796 from bet4it/dylib
Browse files Browse the repository at this point in the history
Fix dynamic linkage on msvc
  • Loading branch information
wtdcode committed Mar 8, 2024
2 parents ba92f79 + 243e9c8 commit 0bca8df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
Expand Down

0 comments on commit 0bca8df

Please sign in to comment.