Skip to content

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

@ntsoftware

Description

@ntsoftware

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");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions