This is a full walkthrough of setting up Rust on Windows using the GNU toolchain via MSYS2 β no Visual Studio, no link.exe
, no tears."
I wanted Rust. I didn't want Visual Studio.
What followed was 3 hours of linker errors, missing DLLs, and yelling at my terminal β but I came out stronger. If you want to set up Rust on Windows without Visual Studio, here's exactly what worked for me.
π― What Weβre Building
Rust + MSYS2 + GCC = β
No Visual Studio + No link.exe = π
Weβll set up a lightweight, open-source Rust environment on Windows using the x86_64-pc-windows-gnu
toolchain and MSYS2.
I assume you have rust installed already if not π Install Rust
π οΈ 1. Install MSYS2 (the Right Way)
- Download from π msys2.org
- Open MSYS2 MinGW 64-bit Terminal (not the default one!)
- Then run:
pacman -Syu
β If it asks you to restart the terminal, do that and run it again.
π§ 2. Install the Toolchain
In MSYS2 MinGW 64-bit Terminal:
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
If you face mirror timeouts (especially common in Africa), update this file:
/etc/pacman.d/mirrorlist.mingw64
Replace with:
Server = https://cdn.jsdelivr.net/msys2/mingw/x86_64/
Server = https://mirror.msys2.org/mingw/x86_64/
Server = https://packages.msys2.org/mingw/x86_64/
Then clean and update again:
pacman -Scc
pacman -Syyu
π§ 3. Switch Rust to the GNU Toolchain if you were using another version
rustup install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
βοΈ 4. Tell Cargo Where Your Compiler Is
Edit this file:
C:\Users\<your_username>\.cargo\config.toml
Add:
[target.x86_64-pc-windows-gnu]
linker = "C:\\msys64\\mingw64\\bin\\gcc.exe"
ar = "C:\\msys64\\mingw64\\bin\\ar.exe"
π§© 5. Fix That Dreaded dlltool
Error
β
Error calling dlltool 'dlltool.exe': program not found
Make sure you have it(dlltool):
where dlltool
Expected:
C:\msys64\mingw64\bin\dlltool.exe
If not, run:
pacman -S mingw-w64-x86_64-binutils --overwrite '*'
Then temporarily fix your PATH
:
$env:PATH="C:\msys64\mingw64\bin;" + $env:PATH
To make it permanent, add it via System Environment Variables.
π 6. Test It Out
cargo new rust_test
cd rust_test
cargo build
π No Visual Studio. No
link.exe
. Just Rust + GCC goodness.
π‘ Bonus Tips from My Pain
- Never run pacman from PowerShell or CMD β MSYS2 only!
- Update your mirrors early if you're outside the US/EU.
-
MSVC-based crates (like
windows-sys
) will complain β avoid them or find GNU alternatives. -
Check your paths β MSYS (
/usr/bin
) and MinGW (/mingw64/bin
) are not the same!
π Final Thoughts
If youβre tired of bloated installs and want to keep things lean and open-source, this setup works beautifully. It took me trial, error, and a bit of cursing to get it right β but now itβs smooth sailing.
If this helped you, drop a β€οΈ or share it. If you ran into a different issue, comment below β letβs help more Rustaceans build without the bloat.
π£οΈ Your Turn:
Have your own story of escaping the grip of Visual Studio? Share it in the comments β letβs make the Windows + Rust experience better for all.
Check me out at theacj.com.ng
Top comments (0)