[Rust installation, Windows] I always had trouble with C++ build tools

I never used Rust with Visual Studio Build Tools (yes, I installed the C++ Tools only) because I always got things like link.exe not found, so I had to always use MinGW and I'm tired of that. It looks like link.exe was just installed on my file system, but its parent directory wasn't added to the environment path automatically by Visual Studio 2022. So I tried to add it manually, but that is very bad for me... And even adding it to path manually, doesn't solve the problem.

image

Here's the actual problem after adding it manually:

C:\Users\Mathe\OneDrive\Documents\Rust Projects\hello>cargo run
   Compiling hello v0.1.0 (C:\Users\Mathe\OneDrive\Documents\Rust Projects\hello)
error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "link.exe" "/NOLOGO" "C:\\Users\\Mathe\\AppData\\Local\\Temp\\rustcPSKWSa\\symbols.o" "C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps\\hello.18ekdciii91d9cgt.rcgu.o" "C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps\\hello.3mgv8a38qdvha68v.rcgu.o" "C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps\\hello.4blvxzusi2g9b5dt.rcgu.o" "C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps\\hello.4lqtostqoys2c3ha.rcgu.o" "C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps\\hello.71dd9iyuihwp9ij.rcgu.o" "C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps\\hello.pkc826w91j8mvcv.rcgu.o" "C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps\\hello.47pjvui635g6kuwt.rcgu.o" "/LIBPATH:C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps" "/LIBPATH:C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-391022a4250a8b9a.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-3069c74fd845ecc2.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-cae8325b8f11cb55.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-6ecbb4a24be3ec33.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-7cef55517a70b408.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libminiz_oxide-d1e72b1788c7e8f6.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libadler-65d80753bac4b1a6.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-932a6231bea08890.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-04ed514427316340.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-9b75e26b1d0a074f.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-95c2795d82b7b742.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-1bf02ac2d8cdb80a.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-117dfa1fe8688bcf.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-9ac5797c0b4842d0.rlib" "C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-ad271357e078d260.rlib" "kernel32.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "ntdll.lib" "msvcrt.lib" "legacy_stdio_definitions.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Users\\Mathe\\OneDrive\\Documents\\Rust Projects\\hello\\target\\debug\\deps\\hello.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\Mathe\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
  = note: LINK : fatal error LNK1181: cannot open input file 'kernel32.lib'


error: could not compile `hello` (bin "hello") due to previous error

Does this walkthrough help: MSVC Prerequistes - The rustup book

It's for Community but it applies to Build Tools too. Make sure you have all the needed components, including the "Windows 11 SDK".

Btw, you shouldn't need to have link in path. Rust can find it regardless.

2 Likes

Solved! ... Just missed the Windows SDK. Like you said, the environment path isn't needed too.