Why release version can running, debug version can't runing?

win10 64bit, MinGW64, rust 1.89.

fn main() {
    println!("Hello world");
}

release can running.

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)

Thank you for your answers!

my first guess is the anti-virus software. try disable it temporarily to see if it works.

1 Like

I have test. It has nothing to do with anti-virus software. when I double-click to run the hello.exe, and the following interface will pop up.

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)

Thank you for your answers!

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?

1 Like

@bjorn3 it's the popup for programs that cannot run on a Windows PC.
Translation (Google Translate):

This app can't run on your PC. To find the version that works on your PC, check with the software publisher.

It could be caused by insufficent permissions or antivirus (#2)

1 Like

The smartscreen popup is say:

This application cannot run on your computer. 
To find a version that works with your computer, consult the software publisher.

I maybe need to upload the file hello.exe so you can figure out why. You can access https://github.com/wqkuang/rust_hello to get this project.

This error appears to mean “is not a valid Win32 application”.

I downloaded your hello.exe and ran file on it, and it says:

hello.exe: PE32+ executable (console) x86-64, for MS Windows

IIRC PE32+ means it’s a 64-bit executable? If that’s the case, then it looks fine.

Just out of curiosity, can you compile/link/run a simple (debug) C or C++ hello world?

1 Like

IIRC it can give that error for a missing import, but I wouldn't expect the gnu toolchain to hit that...

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.


  1. 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. ↩︎

1 Like

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.

yes , I can compile/link/run a simple (debug) C or C++ hello world using MinGW64 On my PC.

Section table is broken in debug version (at the left pane). The right pane is release and seems to be ok.

You can use Far manager with Impex plugin (like the on the screen) or dumpbin to investigate it further, ie:

<Section Table>
  01 /4        VirtSize: 000201D8  VirtAddr:  FFC00000
    raw data offs:   00000458  raw data size: 00020208
    relocation offs: 00000000  relocations:   00000000
    line # offs:     00000000  line #'s:      00000000
    characteristics: 42100040
      INITIALIZED_DATA  DISCARDABLE  READ  ALIGN_1BYTES


!!! Can't access memory at 0x00000458 !!!

  02 .text     VirtSize: 0009C608  VirtAddr:  00001000
    raw data offs:   00020800  raw data size: 0009C800
    relocation offs: 00000000  relocations:   00000000
    line # offs:     00000000  line #'s:      00000000
    characteristics: 60500060
      CODE  INITIALIZED_DATA  EXECUTE  READ  ALIGN_16BYTES


I suspect a linker problem. Try using native x86_64-pc-windows-msvc target and see if it works

2 Likes

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)

Your project compiles and works in my hands with the following config:

rustc 1.89.0 (29483883e 2025-08-04)
stable-x86_64-pc-windows-msvc

same problem in rust1.90, both on gnu and msvc version

That's right, old Binutils produce bad executables when encountering Rust debug info: cross run and cross test failed with Bad EXE format for target x86_64-pc-windows-gnu · Issue #1637 · cross-rs/cross · GitHub

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.