In this episode I investigate an error with the build environment (cargo run
) of my new Rust installation (missing link.exe
).
I'm doing a series of 25 minute sessions where I try to get familiar with the Rust programming language. The blogposts in these series are the notes I took of the lessons learned along the way.
Warning to the reader: As always in this series, these are notes I take as I'm learning, they reflect my current understanding and may be incomplete!
Missing link.exe
In the previous episode, I ran into an issue when trying to compile the hello world project.
cargo run
produced the following error:
error: linker `link.exe` not found
|
= note: The system cannot find the file specified. (os error 2)
note: the msvc targets depend on the msvc linker but `link.exe` was not found
note: please ensure that VS 2013 or VS 2015 was installed with the Visual C++ option
error: aborting due to previous error
error: Could not compile `hello_cargo`.
To learn more, run the command again with --verbose.
Which Visual Studio?
The error mentions, specifically, Visual Studio 2013 or Visual Studio 2015.
On my environment I only have the Community Edition of Visual Studio 2017. Maybe that is not OK or maybe my installation is missing the Visual C++ option?
A thread on the rust-lang.org forum seems to indicate the component we actually need is called Build Tools for Visual Studio 2017.
It can be downloaded from visualstudio.com: Build Tools for Visual Studio 2017
So, I install it:
In the installer, it's called Visual C++ Build Tools.
This thing has been given three names already:
- Visual C++ option
- Build Tools for Visual Studio 2017
- Visual C++ Build Tools
This installs about 1 GB of things on my machine:
Windows 8.1 SDK
Oh no!
While the installation was ongoing, I read further online and learned that what is actually needed is the Windows 8.1 SDK, which is part of the Build Tools for Visual Studio 2017 but not enabled by default.
By default, only the Windows 10 SDK is selected. So I modified the install and add the Windows 8.1 SDK. Interestingly you can pause the installation and modify your original choices.
Installation Completed
After this has been installed, I retry cargo run
. The output is now:
Compiling hello_cargo v0.1.0 (file:///C:/Users/username/Documents/Programming/Training/Rust/hello_cargo)
Finished dev [unoptimized + debuginfo] target(s) in 1.10 secs
Running `target\debug\hello_cargo.exe`
Hello, world!
Success!
Build button?
I'm looking for a button or a shortcut to build the project from within Visual Studio Code, but couldn't find anything yet.
Interestingly, when opening the project in Visual Studio Code, it asked me again to install RLS and the other thing, as seen in the previous Episode.
Conclusion
Besides Rustup and the RLS extension for Visual Studio Code you must have the Windows 8.1 SDK, part of the Build Tools for Visual Studio 2017. I don't think you actually need Visual Studio itself installed.
Note that the Windows 8.1 SDK is not included by default, you have to check it in the installer.
After the compilation succeeded, I tried to look for a "Build" button in my Visual Studio Code environment, but couldn't find any yet.
Next 25 minutes will be about exploring the options of the Visual Studio Code extension some more.