Rust on Windows. Why is it so difficult? Asking for a friend ;-)

I'm a BSD and Linux user.

I sometimes wanted to share my source code with people who are using Windows, so they can compile my programs. It turned out that installing Rust was a hassle for them.

When I visit Install Rust - Rust Programming Language, then it shows me:

It looks like you’re running macOS, Linux, or another Unix-like OS. To download Rustup and install Rust, run the following in your terminal, then follow the on-screen instructions. See "Other Installation Methods" if you are on Windows.

Not sure what people on Windows see.

Clicking on that link (Other Installation Methods), I can get to rustup-init.exe, but after installing Rust, programs won't compile because link.exe isn't found. So I had to search again (did it in past, but I forgot) to figure out there needs to be a linker installed.

But which linker to install? Microsoft has some recommendations:

Install Visual Studio (recommended) or the Microsoft C++ Build Tools

I wanted to let a friend compile a small program for amateur radio, and not have them install a full Visual Studio! Just these dependencies:

[dependencies]
rustyline = "9.1.2"
reqwest = { version = "0.11.10", features = ["blocking"] }
clap = { version = "3.1.18", features = ["derive"] }

So I told them to go for Microsoft C++ Build Tools (after trying with x86_64-w64-mingw32-gcc, which didn't work because of some linker error (don't have the error message anymore).

Trying to install Microsoft C++ Build Tools, there are hundreds of components to pick from? Is it really necessary to install everything? I asked them to install only what sounded to be needed for linking the program, but then:

ld: cannot find -lntdll

Not sure if it was because I didn't install everything or because of a previous try to get x86_64-w64-mingw32-gcc working.

My point is:

Why isn't there a short accessible documentation what to do to get Rust working on Windows without installing a lot of stuff that'ts not needed? Or maybe there exists one and I just didn't find it? Or I can't see it when I'm browsing with Linux, BSD, or Android?

Perhaps someone here can help me out:

  1. What to do to get a Rust compiler and linker running on Windows (without installing lots of stuff that's not needed)?
  2. What is that ntdll and what to do to install it?
  3. Why is Visual Studio recommended? Is it bad to not install it?
  4. Where to find good documentation on it when I would like to help other people installing Rust on Windows?

Your help is very much appreciated, and please forgive me my frustrated tone :wink:.

6 Likes

The Book has a short explanation Installation - The Rust Programming Language

The easiest way to acquire the build tools is to install Build Tools for Visual Studio 2019. When asked which workloads to install make sure “C++ build tools” is selected and that the Windows 10 SDK and the English language pack components are included.

There are at least 10 different options for C++ build tools with various versons and targets. :slightly_frowning_face:

The pc-windows-gnu target works out of the box on Windows without the need for Visual C++ build tools. It's worth noting that rustup-init.exe detects if you don't have the required VC++ components and tells you you'll need to install them or use the gnu target.

The reason it's harder to get set up on Windows is that Windows comes from a end-user focuses history where the end-user isn't expected to be compiling any programs. Additionally, while Linux dynamic linking is an adventure of using the linker to interpret the binary, dynamic linking using DLLs is a (to a first approximation) completely separate system from linking during compilation on Windows.

The most easiest officially supported way to get running is to use the Visual Studio Installer to install the "Desktop Development with C++" module. Unfortunately any other path is very "know what you're doing."

Seeing as you're missing ntdll (as in Windows NT), I suspect you've not installed a Windows SDK, which is required to link against system APIs such as those used by std.

6 Likes

ld: cannot find -lntdll

Btw, ntdll is a low level library and not normally needed. And ld is not the default linker on Windows msvc (that's link.exe). You have to do something extra to make it so.

1 Like

So maybe that was then because I asked my friend to try with x86_64-w64-mingw32-gcc first. Perhaps uninstallation wasn't done properly.

Note that the "Build Tools for Visual Studio" is a separate, smaller thing than the full Visual Studio, and it's all you really need. It's all the way down the bottom of the download page.

I believe this is pretty much the same experience on Mac, where you need to get at least the "XCode Command Line Tools" (from memory?) installer from the app store, the difference being a Mac developer is much more likely to already have needed it installed for various reasons, and it doesn't ask any questions. Oh, and they break on OS updates so you need to update them all the time. (I'm not bitter, why do you ask?)

Anyway, the "Desktop C++" preset gives you a bunch of crap you very likely don't need, like ATL libraries and low level debugging tools. But they're harmless, it has dependency checking, and describes everything so it's easy to strip out stuff you don't think you'll need, and you can just run the installer again to add just the stuff you missed if you find something was needed.

Note that you just need a Windows SDK and a compiler runtime version. It only matters for compatibility, basically, and it will just pick a reasonable default if you have multiple installed and you don't specify which in the compiler args (I've needed to tell Rust to make a build for Windows 7 before, which isn't supprted by the current SDKs any more, for example). Normally you can ignore it completely.

7 Likes

This error will be referring to not being able to find libntdll.a, which describes the exports from ntdll.dll for the MinGW linker. It does look a conflict between bundled and separate broken MinGW versions to me.

(I gave up on getting a version of MinGW to work properly on Windows and hand-wrote an object file generator so my toy programs can include an XML manifest with nothing but the bundled tools.)

1 Like

Thank you for all the responses. With your help I figured it was our attempt to try with x86_64-w64-mingw32-gcc. Just to be safe, we completely removed Rust (rustup self uninstall), installed Visual C++ Build Tools 2019 as suggested, and then reinstalled Rust.

However, rustup proposed to install Windows 10 SDK while it was a Windows 11 machine. We only installed Windows 11 SDK instead, and it seemed fine.

As mentioned above, this sets the minimum version of the binaries they produce. Windows 10 is going to be a safer target for another ~6 years because Win11 has extra hardware requirements that a lot of existing machines don't satisfy.

3 Likes

This isn't quite true, IIRC? Each SDK version exposes a range of supported versions, so a Windows 10 19044.1706 SDK doesn't require that version to run, but it has support for any APIs introduced and occasionally different defaults (eg SPECTRE mitigations), and then you enable those APIs with a target version define.

In general, not something to worry about in either direction, especially for Rust.

Yes, the latest SDK supports previous versions of Windows. See: Windows SDK - Windows app development | Microsoft Developer

For Rust's purposes, the only essential things are a few import libraries used by the std (the windows crate uses its own import libraries). Though the SDK does also come with some other tools that some projects may want to use, especially if they include C++ or want to publish to the store.

1 Like

WTF? Just yesterday I've installed it on Windows 11, it wasn't hard AT ALL D:

Just download the installer, open, type 1, Enter, w8 ... done

Ima guess you already had a dev environment on that box.

2 Likes

It's apparently getting better soon with the next release of rustup: Offer to auto install VS 2022 by ChrisDenton · Pull Request #2954 · rust-lang/rustup · GitHub

2 Likes

If anyone wants to help test this I would very much appreciate it. Both that it works and that the workflow is good.

Note that it currently only auto-installs in the simple case (VS is not installed at all).

Edit: Here's a direct link to the new installer: https://dev-static.rust-lang.org/rustup/archive/1.25.0/x86_64-pc-windows-msvc/rustup-init.exe

Yep .. I realized that later.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.