简体   繁体   English

cpp exe文件适用于wsl但不适用于windows10 cmd

[英]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.我使用命令g++ main.cpp foo.cpp在 WSL 中使用 g++ 制作了一个可执行文件,并且在 WSL 环境中工作正常。

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.但是,在 windows 10 命令行中,当我尝试执行该文件时,它显示由于与 64 位版本的 Windows 不兼容,程序无法启动或运行。 [Unsupported 16-Bit Application] [不支持的 16 位应用程序]

So, the question is "How can I build a 64 or 32-bit executable file with g++ in WSL."因此,问题是“如何在 WSL 中使用 g++ 构建 64 位或 32 位可执行文件。” Currently, I guess I am getting the 16-Bit Version.目前,我想我得到的是 16 位版本。

WSL is a Linux layer, its gcc will generate Linux executables. WSL 是一个 Linux 层,它的gcc将生成 Linux 可执行文件。 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.通过 WSL 运行它们当然会起作用,但是如果您尝试在普通的 Windows 中运行它们,Windows 会对您耸耸肩。

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. 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.该问题与 16 位代码无关,这只是 Windows 对您提供的奇怪可执行文件的最佳猜测。

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 (ie in WSL), and run it on Windows. 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 (ie 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.可执行文件格式有各种特定于操作系统的东西,这使得它们不兼容,甚至在您与操作系统和编译器的标准库交互之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM