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
@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)
I remember installing 2017.
On July 5, 2018 8:03:06 AM PDT, cswinter notifications@github.com wrote:
@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)--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
https://github.com/rust-lang-nursery/rustup.rs/issues/1455#issuecomment-402752792
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
@cswinter I'm not 100% certain, but I suppose it works with the latest 2017 build tools for me.
@AaronM04 well, /nologo is msvc option and the commands you posted link against Windows core libraries. So those cannot be correct options for GNU either.
You should use the msvc toolchain as default toolchain to use the Visual C++ build tools.
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.
Thanks for the help everyone. I fixed this by:
Adding c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64\ to my system Path, then
Installing "Windows 10 SDK (10.0.15063) for Desktop C++" as described at https://github.com/rust-lang/rust/issues/43039
What VS dependency do I need to add to get link.exe? I see closed issues, but no solution. Can someone please offer a link to the correct VC++ version?
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).
I have an issue with VS 2019 Preview 3.0 - on the laptop, rust is not able to find link.exe, while on the desktop it can. I can build fine from the x64 Prompt, but not from the command line.
can someone help me?

can someone help me?
Did you ever solve this? Having the same issue on Windows
@ajess33 where link returning gnu link is completely fine since rust is capable of searching for msvc through the registry and stuff and does not rely on PATH. If rust is invoking gnu link however, then that means your vc++ installation is missing some important component, usually the windows sdk is the most common to be missing.
Hi, I think this problem still exists. I can get cargo to compile and link in the x64 Native Tools Command Prompt as long as I add all the paths but it doesn't work in Powershell generating the same linker error as described above.
Can someone recommend a fix for using with powershell/Visual Studio 2019? The Rust extension for VS also gives me the rustup is not installed error.
Any chance that rustup will get fixed to make this work?
@edwaugh its not clear that you have the same issue - per discord, after you rebooted to activate path, vs works fine, cmd works fine, but powershell invocations aren't working correctly.
Whatever the issue is, I don't think it is within rustup: rustup has correctly added to PATH, and it's proxies seem to be doing the right thing as far as we can tell.
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> ...
Thanks for the help everyone. I fixed this by:
- Adding
c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64\to my system Path, then- Installing "Windows 10 SDK (10.0.15063) for Desktop C++" as described at rust-lang/rust#43039
My PATH was different but this solution worked for me. Thank you!!!!
Most helpful comment
Thanks for the help everyone. I fixed this by:
Adding
c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64\to my system Path, thenInstalling "Windows 10 SDK (10.0.15063) for Desktop C++" as described at https://github.com/rust-lang/rust/issues/43039