rustup: link.exe problem on Windows 10

Hi all, I installed the MS C++ Build Tools as requested by rustup-init.exe and rebooted, but I am unable to build a hello world app with cargo:

? cargo run
   Compiling hello v0.1.0 (file:///C:/Users/myusername/Documents/hello)
error: linking with `link.exe` failed: exit code: 1
  |
  = note: "link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps\\hello-82df257bc2a2633d.10ygozpgsu0ud2lu.rcgu.o" "C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps\\hello-82df257bc2a2633d.1y16o1qfye96o7m0.rcgu.o" "C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps\\hello-82df257bc2a2633d.3rngp6bm2u2q5z0y.rcgu.o" "C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps\\hello-82df257bc2a2633d.4oc10dk278mpk1vy.rcgu.o" "C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps\\hello-82df257bc2a2633d.4xq48u46a1pwiqn7.rcgu.o" "C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps\\hello-82df257bc2a2633d.544l4wfz89vbhoea.rcgu.o" "/OUT:C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps\\hello-82df257bc2a2633d.exe" "C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps\\hello-82df257bc2a2633d.crate.allocator.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\Users\\myusername\\Documents\\hello\\target\\debug\\deps" "/LIBPATH:C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-9f1edc24d0b74e0c.rlib" "C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-2d50f247da360a48.rlib" "C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-eb42664d0182a79c.rlib" "C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-38159e862df1f40b.rlib" "C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-9e685589a65e5f9b.rlib" "C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-cb5a1bd9bdafe27f.rlib" "C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-bace9445355015e4.rlib" "C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-37f282c12d20ae8e.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib"
  = note: /usr/bin/link: extra operand '/LIBPATH:C:\\Users\\myusername\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib'
          Try '/usr/bin/link --help' for more information.


error: aborting due to previous error

error: Could not compile `hello`.

To learn more, run the command again with --verbose.

It appears that it’s running the GNU link command rather than the MSVC one. Could this be a path problem? Here is my path:

C:\Users\myusername\Downloads\cmder_mini\bin;C:\Users\myusername\Downloads\cmder_mini\vendor\conemu-maximus5\ConEmu\Scripts;C:\Users\myusername\Downloads\cmder_mini\vendor\conemu-maximus5;C:\Users\myusername\Downloads\cmder_mini\vendor\conemu-maximus5\ConEmu;C:\Program Files\Docker\Docker\Resources\bin;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Perforce;C:\Program Files\Git\cmd;C:\Users\myusername\.cargo\bin;C:\Users\myusername\AppData\Local\Microsoft\WindowsApps;C:\Users\myusername\AppData\Local\atom\bin;C:\Program Files\Git\mingw64;C:\Program Files\Git\usr\bin;C:\Users\myusername\Downloads\cmder_mini

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 17 (4 by maintainers)

Most upvoted comments

Thanks for the help everyone. I fixed this by:

  1. Adding c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64\ to my system Path, then

  2. Installing “Windows 10 SDK (10.0.15063) for Desktop C++” as described at https://github.com/rust-lang/rust/issues/43039

For people who want to spare time and brain cells, here is how to compile a rust program in clean Windows installation:

Press Win key, search for “powershell”, launch Windows Powershell as administrator.

<# install package manager #>
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

<# install vs shit and rust with ms abi. you may need to reboot afterwards #>
choco install visualstudio2019buildtools visualstudio2019-workload-vctools rust-ms -y --force

<# add built rust software path #>
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";C:\Users\" + $env:USERNAME + "\.cargo\bin", "User")

<# populate env with new binaries installed with package manager and path updates. you need to restart pwsh if this doesn't work #>
refreshenv

<# install pwsh script to import env vars from cmd bat into pwsh, see next command #>
Install-Module -Name WintellectPowerShell -Scope CurrentUser -Confirm:$false -Force -AllowClobber

<# import env vars with paths into pwsh. you need to do this every time you start new pwsh and want to compile rust software #>
Invoke-CmdScript 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat'

You should now be able compile, install and use whatever Rust software you want:

cargo install -f --git <your_github_link>
<rust_program> ...

This is definitely a path problem. Make sure you don’t have a conflicting link.exe on your PATH. You can see the current link.exe by running where link.exe in cmd or Get-Command link.exe in powershell.

can someone help me? image

Rust does not blindly invoke link.exe unless it is unable to locate all the necessary components. If all the necessary components are installed then Rust will be able to locate them itself, no PATH modifications necessary.

When using the Visual Studio Installer please make sure you have at least one of the VC++ 2017 version 15.x tools installed and one of the Windows 10 SDKs (if there are multiple variants for a version, choose the desktop x86 x64 version) installed. If you have both of those components and Rust is still not able to detect VC++, then reach out to me so I can help diagnose the issue (and eventually get that corner case fixed in Rust).

@AaronM04 What version of the build tools did you install? I think Rust specifically requires the Visual C++ Build Tools 2015 which seem hard to come by these days (see https://github.com/rust-lang-nursery/rustup.rs/issues/1454)