Administrator@DESKTOP-CFR0G27 MINGW64 /e/rustProject/hello (master)
$ cargo b -r
Finished `release` profile [optimized] target(s) in 0.13s
Administrator@DESKTOP-CFR0G27 MINGW64 /e/rustProject/hello (master)
$ ./target/release/hello.exe
Hello world
debug can't running
$ cargo r
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s
Running `target\debug\hello.exe`
error: could not execute process `target\debug\hello.exe` (never executed)
Caused by:
%1 不是有效的 Win32 应用程序。 (os error 193)
You can access https://github.com/wqkuang/rust_hello to get this project and hello.exe.
Today(2025/09/16, am, 0:28). I found using rust 1.85.0 will be Ok!!! rust 1.86.0 can reproduce the problem. My gcc is gcc version 7.1.0 (x86_64-posix-seh-rev2, Built by MinGW-W64 project)
Today(2025/09/16, am, 0:28). I found using rust 1.85.0 will be Ok!!! rust 1.86.0 can reproduce the problem. My gcc is gcc version 7.1.0 (x86_64-posix-seh-rev2, Built by MinGW-W64 project)
I can't read Chinese, but that looks like the smartscreen popup of windows defender for uncommon programs. Normally that would have a button to allow anyway though. Are you able to copy-paste the text in that popup to put it in a translator?
Windows Defender is almost always the culprit. Adding a directory exclusion where you keep all of your source code can be helpful, but may not be enough [1].
Windows 11 has Dev Drives to address the problem (not available on Windows 10). For Windows 10, your best bet might be building in WSL.
Anecdotally, one of the projects I work on has a build script that shells out to the git CLI for pretty much every file in the repo. It only takes one or two seconds on macOS and Linux. On Windows, it takes up to a minute to spawn and destroy hundreds of processes. Windows Defender insists on scanning git.exe every time before it is started. I still haven't convinced Defender to stop doing that, even with everything excluded. ↩︎
By any chance, does which ld return something other than /mingw64/bin/ld or /ucrt64/bin/ld? I found that using a version of ld.exe not directly provided by MinGW (e.g., the one bundled with Strawberry Perl iirc) could produce a corrupted binary for some reason.
Thank you response. I found using rust 1.85.0 will be Ok!!! rust 1.86.0 can reproduce the problem. My gcc is gcc version 7.1.0 (x86_64-posix-seh-rev2, Built by MinGW-W64 project)