william
william

Reputation: 52

cpp exe file working on wsl but not working on windows10 cmd

I make an executable file with g++ in WSL with the command g++ main.cpp foo.cpp and is working fine in WSL environment.

But, In windows 10, command line, when I try to execute the file, it says The program cannot start or run due to incompatibility with 64-bit versions of Windows. [Unsupported 16-Bit Application]

So, the question is "How can I build a 64 or 32-bit executable file with g++ in WSL." Currently, I guess I am getting the 16-Bit Version.

Upvotes: 0

Views: 467

Answers (2)

Macke
Macke

Reputation: 25690

I'd say that the file formats for executables are different in Linux and Windows, so you can't take something you build n Linux (i.e. in WSL), and run it on Windows.

There's all kinds of OS-specific things to the executable file format that makes them incompatible, even before you get to interacting with the OS and the compiler's stdlib.

Upvotes: 0

Blindy
Blindy

Reputation: 67419

WSL is a Linux layer, its gcc will generate Linux executables. Running them through WSL will of course work, but if you try to run them in plain Windows will have Windows shrug its shoulders at you.

If you want to compile Windows executables from Linux you need to use gcc multi-targetting, essentially using the Windows gcc version compiled under Linux.

The problem has nothing to do with 16-bit code, that's just Windows' best guess at the weird executable you give it.

Upvotes: 4

Related Questions