Rust not compiling project - exit code 1

Hi, I'm unable to compile a Rust project on windows because of this error:

error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: (omitted, very long)
  = note: ld: cannot find -lshlwapi: No such file or directory

I have installed Rust using the x86_64-pc-windows-gnu version, and a hello world cargo project compiles file.
Thanks for any help!

shlwapi is a Windows system library. the rust toolchain only ships minimal mingw32/64 libraries required to build rust code. apparently certain crate in your project dependencies requires additional foreign libraries to link. the library is included in standard mingw32/64 installation though, you can install mingw32/64. alternatively, you can install msvc and switch to the -msvc abi rust toolchain.

ps: I think the gnu linker (and rust-lld too) does support link against .lib files, but you still need to install the WindowsKit SDK from microsoft to get the library files.

It seems shlwapi does not require WindowsKit SDK. I have only MinGW installed and I have this library at MinGW\x86_64-w64-mingw32\lib\libshlwapi.a. So, installing only MinGW should be sufficient.

yes, as I said, shlwapi is included in standard mingw64 installation.

I mentioned the WindowsKit SDK as a side note about linking against *.lib files using the gnu linker, for example, if I add a build script with println!("cargo:rustc-link-search=C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22000.0/um/x64"), I can link against all the WindowsKit *.lib files just fine using the gnu abi toolchain.

actually, the gnu linker can link against "normal" *.dll files directly, normal meaning the dll doesn't do weird stuff like loader forwarding or exporting only using cardinals etc.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.