Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustdoc: fatal error LNK1181: cannot open input file 'windows.lib' on windows #99466

Closed
btielen opened this issue Jul 19, 2022 · 7 comments
Closed
Labels
C-bug Category: This is a bug.

Comments

@btielen
Copy link

btielen commented Jul 19, 2022

While working with rustdoc I have a markdown file with the following contents:

Some docs

extern crate tokio;

#[tokio::main]
async fn main() { }

running rustdoc src/some_docs.md --test --edition 2018 -L target/debug/deps

produces the error

= note: LINK : fatal error LNK1181: cannot open input file 'windows.lib'

This happens when I am using the Tokio crate. On Ubuntu and MacOS everything works as expected, on Windows the tests fail in a linking error. Did I do something wrong?

Steps to reproduce

A minimal example:

  • git clone https://github.com/btielen/rustdocwindows.git
  • cd rustdocwindows
  • cargo build
  • rustdoc src/some_docs.md --test --edition 2018 -L target/debug/deps

Environment

  • Windows 10
  • stable-x86_64-pc-windows-msvc (default)
  • rustdoc 1.62.0 (a8314ef 2022-06-27)
  • rustc 1.62.0 (a8314ef 2022-06-27)
@btielen btielen added the C-bug Category: This is a bug. label Jul 19, 2022
@jyn514
Copy link
Member

jyn514 commented Jul 19, 2022

This is fascinating, I've wanted to add links in markdown files for ages and never thought of using -L. Added a note to #77974.

I'm not sure why this would fail and I don't have a windows crate to test - can you rerun rustdoc with RUSTDOC_LOG=rustc_metadata=info so I can see why windows.lib is being loaded?

@jyn514
Copy link
Member

jyn514 commented Jul 19, 2022

also if you can find some way to show the linker command that's being invoked, that would be helpful - I think -v may do it?

@btielen
Copy link
Author

btielen commented Jul 19, 2022

@jyn514

Not sure how I get the rustc_metadata, but here is the complete error:

running 1 test
test src/some_docs.md - _::Error (line 14) ... FAILED

failures:

---- src/some_docs.md - _::Error (line 14) stdout ----
error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.32.31326\\bin\\HostX64\\x64\\link.exe" 
"/NOLOGO" "C:\\Users\\BENNO~1.LAP\\AppData\\Local\\Temp\\rustckeLD8R\\symbols.o" 
"C:\\Users\\BENNO~1.LAP\\AppData\\Local\\Temp\\rustdoctesteriAMV\\rust_out.rust_out.921f0e3c-cgu.0.rcgu.o" 
"C:\\Users\\BENNO~1.LAP\\AppData\\Local\\Temp\\rustdoctesteriAMV\\rust_out.4jh3562snej2r6lm.rcgu.o" 
"/LIBPATH:target/debug/deps"
 "/LIBPATH:C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libtokio-475c740a026df197.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libnum_cpus-a41762073fbff5e0.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libsocket2-af2374001ac84e76.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libmemchr-2d2995cb1b206dfc.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libonce_cell-c715be824e7a7cac.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libbytes-886dc47712887a58.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libmio-d5c1842815a5b615.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\liblog-80e233060601556d.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libpin_project_lite-e6398ca62c762a3b.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libwinapi-dd92b06c44063101.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libparking_lot-c9e40f63faa54b0e.rlib" 
"C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libparking_lot_core-38a0cc33576f5a1c.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libwindows_sys-0f71026276f686a8.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libcfg_if-5321058e3340cc33.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libsmallvec-0ad84c6b5cb41103.rlib" 
"C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\liblock_api-b2ed4988a48945ef.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\source\\repos\\rustdocwindows\\target\\debug\\deps\\libscopeguard-fa0df20a1b9200d1.rlib" 
"C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-1cd530251ef8500f.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-8749f5778873ad0b.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-952a244e6b15fd3d.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-d590b5e29f586f0c.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-157899a56f45c8e0.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libminiz_oxide-7b45cc2f3e360e16.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libadler-20c8aee5cf2ca628.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-601e4def09298a16.rlib" "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-6bfe55bee864f405.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-2dcf1993985aac9f.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-df8a6f52e5519032.rlib" 
"C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-170085950b44d410.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-4f71a076c7db927f.rlib"
 "C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-d75ffa8a17ba1137.rlib" 
"C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-6f60f6a23a58b163.rlib"
 "ntdll.lib" "advapi32.lib" "cfgmgr32.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "ntdll.lib"
 "opengl32.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "windows.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "msvcrt.lib"
 "/NXCOMPAT" "/LIBPATH:C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" 
"/OUT:C:\\Users\\BENNO~1.LAP\\AppData\\Local\\Temp\\rustdoctesteriAMV\\rust_out"
 "/OPT:REF,NOICF" "/DEBUG" 
"/NATVIS:C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" 
"/NATVIS:C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis"
 "/NATVIS:C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis"
 "/NATVIS:C:\\Users\\Benno.LAPTOP-SOMENAME\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
  = note: LINK : fatal error LNK1181: cannot open input file 'windows.lib'

Edit: added some enters for readability.

@tyranron
Copy link

tyranron commented Nov 1, 2022

Any news on this? This is reproducible in GitHub Actions on windows-latest.

@ChrisDenton
Copy link
Member

ChrisDenton commented Nov 1, 2022

So I guess this is because rustdoc is being used directly instead of via cargo so the Windows crate's build script doesn't get to add the library's directory to the linker search path.

You'd need to add it manually. It'll be something like:
CARGO_HOME\registry\src\suiyiyu.us.kg-1ecc6299db9ec823\windows_x86_64_msvc-0.32.0\lib

Where CARGO_HOME is cargo's home directory and the suiyiyu.us.kg- part may differ. You can probably get the crate's manifest directory via cargo metadata and then append lib.

@tyranron
Copy link

tyranron commented Nov 2, 2022

@ChrisDenton

You can probably get the crate's manifest directory via cargo metadata and then append lib.

Thanks! That did the trick:

rustdoc src/some_docs.md --test --edition 2018 -L target/debug/deps \
  $(cargo metadata -q | jq -r '.packages[] | select(.name == "windows_x86_64_msvc") | .manifest_path' | sed -e 's/^/-L /' -e 's/Cargo.toml/lib/')

@jyn514
Copy link
Member

jyn514 commented Nov 2, 2022

Sounds like this isn't a bug.

@jyn514 jyn514 closed this as completed Nov 2, 2022
tyranron added a commit to cucumber-rs/cucumber that referenced this issue Nov 2, 2022
tyranron added a commit to graphql-rust/juniper that referenced this issue Nov 2, 2022
zalanlevai added a commit to zalanlevai/mutest-rs that referenced this issue Aug 3, 2024
When running UI tests we invoke mutest-driver directly, rather than through Cargo, which means we have to add `windows.lib` to the linker search path manually. See rust-lang/rust#99466 for more details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants