cross icon indicating copy to clipboard operation
cross copied to clipboard

Build for `x86_64-pc-windows-gnu` leads to "The specified executable is not a valid application for this OS"

Open myz-dev opened this issue 1 year ago • 1 comments

Checklist

Describe your issue

Hi,

cross compiling from my Linux VM (Ubuntu) for my Windows machine does produce non-runnable executables in debug mode.

If I compile my executable (in this case just the cargo init hello world project) with this command: cross build --target x86_64-pc-windows-gnu

I get the following output when trying to run the built .exe on Windows:

history_versions.exe                                                                  100% 2611KB  52.0MB/s   00:00
PS C:\Users\the\path\> .\history_versions.exe
ResourceUnavailable: Program 'history_versions.exe' failed to run: An error occurred trying to start process 'C:\Users\the\path\history_versions.exe' with working directory 'C:\Users\the\path\'. The specified executable is not a valid application for this OS platform.At line:1 char:1
+ .\history_versions.exe
+ ~~~~~~~~~~~~~~~~~~~~~~.

Interestingly, a binary produced by the command cross build -r --target x86_64-pc-windows-gnu runs as expected (prints hello world to the open PowerShell console). This means my program runs in release mode, but not in debug mode.

I am trying to run the executable in an open PowerShell console like this: PS C:\Users\the\path\> .\history_versions.exe

I think I am using the correct target.

My PC has the processor Intel(R) Core(TM) Ultra 7 165H 1.40 GHz and the Windows "System Type" info box says (in German) "64-Bit-Betriebssystem, x64-basierter Prozessor".

What target(s) are you cross-compiling for?

x86_64-pc-windows-gnu

Which operating system is the host (e.g computer cross is on) running?

  • [ ] macOS
  • [ ] Windows
  • [x] Linux / BSD
  • [ ] other OS (specify in description)

What architecture is the host?

  • [x] x86_64 / AMD64
  • [ ] arm32
  • [ ] arm64 (including Mac M1)

What container engine is cross using?

  • [x] docker
  • [ ] podman
  • [ ] other container engine (specify in description)

cross version

cross 0.2.5 (9e2298e 2025-04-28)

Example

This produces a binary that does not work on my Windows machine.

cross build --target x86_64-pc-windows-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.86.0 (05f9846f8 2025-03-31)

info: checking for self-update
   Compiling history_versions v0.1.0 (/path/history_versions
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.19s

This produces a binary that works on my Windows machine.

 cross build -r --target x86_64-pc-windows-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.86.0 (05f9846f8 2025-03-31)

info: checking for self-update
   Compiling history_versions v0.1.0 (/path/history_versions)
    Finished `release` profile [optimized] target(s) in 0.18s

Additional information / notes

Both binaries are transferred using SCP on Windows (PowerShell): scp user@ip:/path/history_versions/target/x86_64-pc-windows-gnu/release/history_versions.exe ./

myz-dev avatar May 07 '25 09:05 myz-dev

This is a duplicate

Emilgardis avatar May 07 '25 10:05 Emilgardis