Skip to content

Instantly share code, notes, and snippets.

@Mefistophell
Last active August 29, 2025 16:15
Show Gist options
  • Select an option

  • Save Mefistophell/9787e1b6d2d9441c16d2ac79d6a505e6 to your computer and use it in GitHub Desktop.

Select an option

Save Mefistophell/9787e1b6d2d9441c16d2ac79d6a505e6 to your computer and use it in GitHub Desktop.
How to Compile a Rust Program on Mac for Windows
  1. Install target mingw-w64: brew install mingw-w64
  2. Add target to rustup: rustup target add x86_64-pc-windows-gnu
  3. Create .cargo/config
  4. Add the instructions below to .cargo/config
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
  1. Fix cert
cp -f /usr/local/Cellar/mingw-w64/7.0.0_1/toolchain-x86_64/x86_64-w64-mingw32/lib/{,dll}crt2.o `rustc --print sysroot`/lib/rustlib/x86_64-pc-windows-gnu/lib
  1. And finally, run: cargo build --target=x86_64-pc-windows-gnu --verbose

Useful commands: rustup show rustup target list

@LiamCahill
Copy link

Super helpful! Thank you.

@52617365
Copy link

How would I do this for the x86_64-pc-windows-msvc target? When I compile it says I'm missing lib.exe.

@chenyanchen
Copy link

God plz, one clear solution here!

Copy link

ghost commented Oct 23, 2023

Hello! What about rust analyser? It still shows compatibility errors

@fatheyabdelslam
Copy link

Is this solution works when my mac have m1 chip

@xavierbradford
Copy link

Is this solution works when my mac have m1 chip

yes worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment