With Rust gaining more and more popularity due to newer technologies such as Web3, developers have started to learn Rust to not only keep up with new trends but also expand their skillset. However, it is always disappointing whenever you run into errors when starting to execute code in a new programming language such as Rust.

In my case, I installed Rust in Windows and attempted to build my first simple “Hello World” piece of code in Rust using cargo build. However, I came across the following error: Error link.exe failed exit code 1.

Note: I installed Rust in both, Windows Subsystem for Linux (WSL) and Windows. This error only appeared after installing Windows.

Error link.exe failed exit code 1

The Solution

After checking the rustup book, it talks about Rust having two ABIs on MSVC and the GNU. By default, Rust uses the MSVC ABI, which it was causing the Error link.exe failed exit code 1.

After installing and configuring the Rust GNU ABI, I didn’t have issues after running the cargo build command.

To install the GNU ABI, use the following command:

rustup toolchain install stable-gnu

Depending on the Windows system you have, whether it is 32-bit or 64-bit, it will install a specific target. Since I have Windows 64-bit, it installed the target x86_64-pc-windows-gnu. Check out the full list of tier 1 targets supported in Rust.

Rust GNU ABI installed

The rustup book recommends the following command to change the Rust configuration in Windows.

rustup set default-host x86_64-pc-windows-gnu

However, that did not work for me. If that doesn’t work for you either, use the following command:

rustup default stable-x86_64-pc-windows-gnu

Now, try one more time running the cargo build command. You should not see errors when building the Rust executable file.

Note: For more information about how Rust works on Windows, it is suggested to read this, which you can find in the rustup book.

Was this article helpful?

Share your thoughts by replying on Twitter of Become A Better Programmer or to personal my Twitter account.

Author