libssh-rs icon indicating copy to clipboard operation
libssh-rs copied to clipboard

Linker fails for the x86_64-pc-windows-gnu target

Open ntsoftware opened this issue 3 months ago • 1 comments

I am getting a linker error when trying to build for the x86_64-pc-windows-gnu target. My executable links correctly for the x86_64-pc-windows-msvc target.

The root cause is that the MSVC and GNU compiler expect linker libraries to be specified differently (i.e., with or without the lib prefix). The patch below applied to build.rs fixes the problem.

Compiler detection is based on the scheme implemented in the openssl-sys crate.

--- ./vendor/libssh-rs-sys-0.2.6/build.rs
+++ ./patch/libssh-rs-sys-0.2.6/build.rs
@@ -260,8 +260,15 @@
     cfg.compile("libssh");

     if target.contains("windows") {
-        println!("cargo:rustc-link-lib=libcrypto");
-        println!("cargo:rustc-link-lib=libssl");
+        if target.contains("windows-msvc") {
+            // target `windows-msvc` expects `lib` prefix
+            println!("cargo:rustc-link-lib=libcrypto");
+            println!("cargo:rustc-link-lib=libssl");
+        } else {
+            // target `windows-gnu` adds the `lib` prefix
+            println!("cargo:rustc-link-lib=crypto");
+            println!("cargo:rustc-link-lib=ssl");
+        }
         println!("cargo:rustc-link-lib=crypt32");
         println!("cargo:rustc-link-lib=user32");
         println!("cargo:rustc-link-lib=shell32");

ntsoftware avatar Oct 28 '25 11:10 ntsoftware