windows下运行linux gcc编译的程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6478788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:44:26  来源:igfitidea点击:

Running linux gcc-compiled program under windows

cwindowslinuxgcccygwin

提问by Matteo Monti

Ok, guys, hope this is quite a simple question: is there any way to run a C program compiled under linux with gcc on a windows operating system? Please don't tell me to recompile it under windows, since I already tried but looks like no c windows compiler has 128 bit native type, and using bignum libraries makes my program like 10 to 100 times slower. Is there any way to actually RUN the linux binary under windows? Someone told me something about cygwin, but I don't know where to get started with it. (My program should be portable as well, so I souldn't need to install programs and stuff on my machine).

好的,伙计们,希望这是一个非常简单的问题:有没有办法在 Windows 操作系统上运行在 linux 下使用 gcc 编译的 C 程序?请不要告诉我在 windows 下重新编译它,因为我已经尝试过但看起来没有 c windows 编译器具有 128 位本机类型,并且使用 bignum 库会使我的程序慢 10 到 100 倍。有没有办法在windows下实际运行linux二进制文件?有人告诉我一些关于 cygwin 的事情,但我不知道从哪里开始。(我的程序也应该是可移植的,所以我不需要在我的机器上安装程序和东西)。

Thank you very much!! Matteo

非常感谢!!马泰奥

回答by Charlie Martin

No direct way. A Linux executable has a radically different format than Windows. There are several other options.

没有直接的办法。Linux 可执行文件的格式与 Windows 完全不同。还有其他几种选择。

  • cygwin. Compile the program with GCC under cygwin. I believe that will build a windows exe that uses the cygwin compatibility layer.

  • install a VM like VBox. Install a Linux in the VBox. Run the program there.

  • http://www.andlinux.orghas a framework for doing this. I've never tried it, but there is a video tutorial http://www.youtube.com/watch?v=nULDHPCm9p4.

  • 赛格温。在cygwin下用GCC编译程序。我相信这将构建一个使用 cygwin 兼容层的 windows exe。

  • 安装一个像 VBox 这样的虚拟机。在 VBox 中安装 Linux。在那里运行程序。

  • http://www.andlinux.org有一个框架可以做到这一点。我从未尝试过,但有一个视频教程http://www.youtube.com/watch?v=nULDHPCm9p4

回答by David Heffernan

Please don't tell me to recompile it under windows

请不要告诉我在windows下重新编译

You'll have to recompile it under Windows. Sorry!

您必须在 Windows 下重新编译它。对不起!

If you really can't find a compiler with support for 128 bit integers you should use some assembler to replicate the instructions that you Linux compiler emits.

如果你真的找不到支持 128 位整数的编译器,你应该使用一些汇编器来复制你的 Linux 编译器发出的指令。

回答by goldenmean

Use a Virtual machine for Linux as Guest OS on your Host Windows OS. Run your executable under the VM. But compiling under gcc-cygwin combine is best bet.

使用 Linux 虚拟机作为主机 Windows 操作系统上的来宾操作系统。在 VM 下运行您的可执行文件。但是在 gcc-cygwin combine 下编译是最好的选择。

回答by T S

It seems to me, that flinuxcould do it.

在我看来,flinux可以做到。

From the description:

从描述来看:

... is a dynamic binary translator ... capable of running unmodified Linux binaries on Windows ...

... 是一个动态二进制转换器 ... 能够在 Windows 上运行未经修改的 Linux 二进制文件 ...

Note: I've not tested this.

注意:我没有测试过这个。

回答by T S

Since Windows 10 Anniversary Update, Windows is able to natively run Linux binaries via Windows Subsystem for Linux(WSL), commonly known as Bash on Ubuntu on Windows.

自 Windows 10 周年更新以来,Windows 能够通过Windows Subsystem for Linux(WSL)本地运行 Linux 二进制文件,通常称为Bash on Ubuntu on Windows.

See https://msdn.microsoft.com/en-us/commandline/wsl

请参阅https://msdn.microsoft.com/en-us/commandline/wsl

After installation, you can open a bash session, navigate to /mnt/<driveletter>/<path to your program>and run your executable as if you were running Linux.

安装后,您可以打开 bash 会话,导航到/mnt/<driveletter>/<path to your program>并运行您的可执行文件,就像您在运行 Linux 一样。

Note: WSL is still beta.

注意:WSL 仍然是测试版。