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

link.exe problem on Windows 10 #1455

Closed
AaronM04 opened this issue Jul 3, 2018 · 17 comments
Closed

link.exe problem on Windows 10 #1455

AaronM04 opened this issue Jul 3, 2018 · 17 comments

Comments

@AaronM04
Copy link

AaronM04 commented Jul 3, 2018

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
@cswinter
Copy link

cswinter commented Jul 5, 2018

@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 #1454)

@AaronM04
Copy link
Author

AaronM04 commented Jul 5, 2018 via email

@quixoticaxis
Copy link

quixoticaxis commented Jul 6, 2018

@cswinter I'm not 100% certain, but I suppose it works with the latest 2017 build tools for me.

@quixoticaxis
Copy link

quixoticaxis commented Jul 6, 2018

@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.

@mzji
Copy link

mzji commented Jul 6, 2018

You should use the msvc toolchain as default toolchain to use the Visual C++ build tools.

@Diggsey
Copy link
Contributor

Diggsey commented Jul 8, 2018

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.

@Diggsey Diggsey closed this as completed Jul 8, 2018
@AaronM04
Copy link
Author

AaronM04 commented Jul 9, 2018

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 Cannot link with Win32 libraries using the MSVC toolchain rust#43039

@theronic
Copy link

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?

@retep998
Copy link
Member

retep998 commented Feb 2, 2019

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).

@high1
Copy link

high1 commented Feb 17, 2019

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.

@Mignet
Copy link

Mignet commented Nov 12, 2019

can someone help me?
image

@ajess33
Copy link

ajess33 commented Feb 14, 2020

can someone help me?
image

Did you ever solve this? Having the same issue on Windows

@retep998
Copy link
Member

@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.

@edwaugh
Copy link

edwaugh commented Jun 13, 2020

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?

@rbtcollins
Copy link
Contributor

@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.

@ghost
Copy link

ghost commented Sep 1, 2020

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> ...

@ghost
Copy link

ghost commented Apr 9, 2021

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 rust-lang/rust#43039

My PATH was different but this solution worked for me. Thank you!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests