Repository: rust
Issue: Inconsistent `#[link(name = "")]` resolution on Windows
Labels: O-windows-msvc

<!-- Thanks for filing a 🐛 bug report 😄! -->

**Background**

We have a Rust project (lets call it `dylib`) where we want to produce a shared library (.dll, .dylib, .so) for various platforms. As part of the build process we also want to verify the provided headers match the library. 

To do that we have a separate project `dylib_test`, where we extract C doc tests into individual `generated_nnn.c` files, produce a `generated.rs` file that knows all C tests, and emits a `#[test]` for each, which we then want to run with `cargo test`.

The `dylib` project should only emit a `cdylib`, and the `dylib_test` should only link against that `cdylib`, to make sure the actual .dll, ... works.  


**Problem**
When linking against `dylib` from the `dylib_test` crate, the `#[link(name = "dylib")]` attribute behaves inconsistently. On Mac and Linux the attribute works. On Windows, it fails with an 

```
error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.21.27702\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.17sc3p6xub1nskk5.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.1d4yl2ra8f02uq65.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.2boci68ky9pbilmt.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.2kg3da7ad2y6u5t4.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.328elmwbbr69laus.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.3pjpoaqleh1qku54.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.48cxjx0647kyqroa.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.4xn06m0s17xpy7q7.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.bdw34kj2m6ietun.rcgu.o" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.dxf6w5mo3hfjrm.rcgu.o" "/OUT:D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.exe" "D:\\Development\\Source\\rust_issues\\target\\debug\\deps\\dylib_test-16b85ad62e2643c4.3tou2046e23p3ckg.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:D:\\Development\\Source\\rust_issues\\target\\debug\\deps" "/LIBPATH:D:\\Development\\Source\\rust_issues\\target\\debug\\build\\dylib_test-df967a17b396e952\\out" "/LIBPATH:C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "dylib.lib" "test_harness.lib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libtest-5868cd1efdb1a14a.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libterm-4a1cd4f9337faede.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libgetopts-c94244661cc3c49c.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunicode_width-5d83c260a3fd1c81.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-69ffdb8026c42481.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-324700ef1bcafc8b.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-66fccb33cfc77b7d.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-429461051376b1a5.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-16c7dc58d869d64a.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-b5f6113de773ee4b.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-52ee0b65e04bcb17.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-eee1f1d0cc78c8f9.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-f5bd27a471d11e8c.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-bb531cfdfdeadec5.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-48d94702399abeaa.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-edaeab1200806e65.rlib" "C:\\Users\\rb\\.rustup\\toolchains\\nightly-2019-07-08-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-5cb137db32dc726e.rlib" "kernel32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'dylib.lib'
```  

I believe this is because Rust on Windows produces a `dylib.dll` and `dylib.dll.lib` (instead of a `dylib.lib`). When then resolving the library Rust apparently isn't aware that to resolve `name="dylib"` it should not only look for the (`dylib.lib`, `dylib.dll`) pair, but instead also for the (`dylib.dll.lib`, `dylib.dll`) pair.



**Steps**
1. Clone https://github.com/ralfbiedert/rust_issues/tree/dylib_issues
2. Run `cargo test` (on Windows)

**Possible Solution(s)**
When given a `#[link(name = "dylib")]`, consider to look for `dylib.dll.lib` on Windows.

The current workaround is to specify `#[link(name = "dylib.dll")]`, but from a cross-platform perspective that feels inconsistent. 

**Notes**

Output of `cargo version`:

<!-- Also, any additional context or information you feel may be relevant to the issue. -->
<!-- (e.g rust version, OS platform/distribution/version, target toolchain(s), release channel.. -->
`cargo 1.37.0-nightly (4c1fa54d1 2019-06-24)`
`rustc 1.38.0-nightly (6e310f2ab 2019-07-07)`   
`x86_64-pc-windows-msvc`