Why is MSVC not installing or being recognized by Rust?
Asked Answered
H

3

6

I've tried this repeatedly and still can't figure out where I'm going wrong. I installed Rust from the official website (version 1.44.1), and I can run rustc --version and get the right result. I can create a new project, but when I run cargo test or cargo build, I get errors.

   Compiling hello-rust v0.1.0 (C:\Projects\rust-test\hello-rust)
error: linking with `link.exe` failed: exit code: 1
  |
  = note: "link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.2475ppgeya7982p6.rcgu.o" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.2k8om5gztlm4khis.rcgu.o" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.2npazqbfnne9a4sz.rcgu.o" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.31mw3i7sxv4jy5mf.rcgu.o" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.39lo872ze2g8kjy6.rcgu.o" "/OUT:C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.exe" "C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps\\hello_rust-3bd7255de8fc516c.3pzk8mfjqu22abeg.rcgu.o" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis" "/LIBPATH:C:\\Projects\\rust-test\\hello-rust\\target\\debug\\deps" "/LIBPATH:C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libtest-ce9bcda9bff89d22.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libterm-5685a6e382a0344d.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libgetopts-9672beb79727d086.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunicode_width-0b6119489f498de7.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_std-f43d3b6a5d7adb85.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-13b0a7dd239e134e.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-c6983deeb3795666.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-fb1f6de11ac9d69b.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-09135599e2aa779b.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libbacktrace-4aec9f98c25f9f5d.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-29671087b5d92459.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-7c5d84958fafcb64.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-c820fe24a63d105a.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-eab51dcd5481cddb.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-da92c312ae6fecdd.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-693c88df9572eb34.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-b5aae910499df009.rlib" "C:\\Users\\Jaden\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-9a7454af4f639d0b.rlib" "kernel32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
  = note: /usr/bin/link: extra operand ‘/LIBPATH:C:\\Users\\Jaden\\.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-rust`.

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

My research has turned up something about MSVC not being set up properly or something missing from the PATH variable. What does this error mean? I have Visual Studio 2017 installed (just the basics, I didn't check any of the workloads or individual components), and to my knowledge, that is MSVC (Microsoft Studio Visual C++). I'm new to Rust and low-level coding in general (I'm a Python/JavaScript guy), so I don't really understand what I need to do here. Could anyone give me guidance here?

Why is MSVC not installing or being recognized by Rust? What could cause this? How can I fix it?

Haileyhailfellowwellmet answered 26/6, 2020 at 2:21 Comment(2)
How did you install Rust? The rustup-init installer has a very clear notice about the need to install Visual C++ prerequisites with links and instructions on what you need to select in the installer.Yung
Kenny Kerr has published an article with detailed instructions on getting a Rust environment set up on Windows: Rust: getting started.Ralleigh
H
6

I happened to find the answer by myself which I didn't find documented anywhere with regards to Rust. I searched longer about installing MSVC and found this Microsoft page: https://learn.microsoft.com/en-us/cpp/build/vscpp-step-0-installation?view=vs-2019

For core C and C++ support, choose the "Desktop development with C++" workload.

I modified my installation and selected the Desktop development with C++ workload. That worked!

Haileyhailfellowwellmet answered 26/6, 2020 at 2:48 Comment(0)
Y
4

When you install Rust using rustup-init.exe it should automatically detect whether you have the Microsoft C++ build tools installed. If they are not installed, it will give you a detailed message on how to install them as the very first thing.

This is what it looks like on Windows 10:

Rust Visual C++ prerequisites

Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
later, but they don't seem to be installed.

The easiest way to acquire the build tools is by installing Microsoft
Visual C++ Build Tools 2019 which provides just the Visual C++ build
tools:

  https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019

Please ensure the Windows 10 SDK and the English language pack components
are included when installing the Visual C++ Build Tools.

Alternately, you can install Visual Studio 2019, Visual Studio 2017,
Visual Studio 2015, or Visual Studio 2013 and during install select
the "C++ tools":

  https://visualstudio.microsoft.com/downloads/

Install the C++ build tools before proceeding.

If you will be targeting the GNU ABI or otherwise know what you are
doing then it is fine to continue installation without the build
tools, but otherwise, install the C++ build tools before proceeding.

Continue? (Y/n)
Yung answered 26/6, 2020 at 3:39 Comment(1)
@JadenBaptista They're not. "Visual C++ Build Tools" are equivalent to the "Visual C++ build tools" that they recommend you install as the easiest method in the first part, which they also include a link to and tell you exactly which components to select. If you for some reason choose the second option, "Visual C++ Build Tools" are included as part of the "Desktop development with C++" workload, but you can select them on their own under the "Individual components" tab. However, they are not labeled as "C++ tools" in VS2019, so that part of the message probably needs updating to be accurate.Yung
O
-1

Make sure you have the Windows SDK installed.

Oregano answered 1/8 at 2:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.