在Windows上运行用Linux编写的C程序 [英] Run C program written in Linux on Windows

查看:70
本文介绍了在Windows上运行用Linux编写的C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用Linux编写的运行良好的C程序.现在,我想在Windows上运行它.

I have C program which I wrote in Linux that runs very well. Now I want to run it on Windows.

如何在Windows上轻松运行它?

How do I easily run it on Windows?

推荐答案

详细说明 jartieda ...

Cygwin 试图在本机Windows进程中模拟(几乎)完整的POSIX执行环境.它足够完整,以至于可以使用熟悉的轻松地编译并运行大量的Unix应用程序代码.制作&&进行安装习惯用语.通过提供一个使用Windows API模拟POSIX系统调用的DLL来完成此技巧.基于此,您将获得完整的GCC工具链,bash和您习惯的所有常用命令行实用程序.缺点是编译后的程序依赖于Cygwin DLL,这使得将结果传递到尚未安装Cygwin且其用户不想使用Unix shell的系统上非常棘手.

Cygwin is an attempt to emulate a (nearly) complete POSIX execution environment in a native Windows process. It is complete enough that a surprising amount of Unix application code simply compiles and runs using the familiar ./configure && make && make install idiom. This trick was done by supplying a DLL that emulates POSIX system calls using the Windows API. Based on that, you get a complete GCC toolchain, bash, and all the usual command line utilities you are used to. One downside is that the compiled program is dependent on the Cygwin DLL, which makes it tricky to deliver the result to a system that does not already have Cygwin installed and whose user doesn't want to use a Unix shell.

MinGW 是GCC工具链的一个端口,可生成依赖于众所周知的Windows应用程序(以及随Windows一起分发)MSVCRT.DLL C运行时库.它没有尝试模仿POSIX操作系统,但是大多数基于标准C库的应用程序通常会在本质上保持不变.

MinGW is a port of the GCC toolchain that generates native Windows applications that depend on the well known (and distributed with Windows itself) MSVCRT.DLL C runtime library. It makes no attempt to emulate a POSIX operating system, but applications that are mostly based on the standard C libraries, will often build essentially unchanged.

MSYS 是一个编译时环境,它提供了足够的Unix实用程序(包括bash)来经常允许 ./configure 运行,如果项目支持结果,请使用MinGW的GCC完成构建.结果是本机Windows可执行文件,除了MSVCRT.DLL之外,该可执行文件不依赖于您没有故意使用的任何DLL.尽管MSYS环境本身是Cygwin项目早期版本的分支,但其主要目的是用于提供一个类似Unix的地方来编译本机Windows应用程序:通常, not 不能构建新的Windows应用程序.应用程序基于其运行时环境.

MSYS is a compile-time environment that provides enough Unix utilities (including bash) to often allow ./configure to run, and if the project supports the results, finish the build with MinGW's GCC. The result is a native Windows executable that does not depend on any DLLs you don't deliberately use aside from MSVCRT.DLL. Although the MSYS environment itself was a fork of an early version of the Cygwin project, it is primarily intended to be used to provide a unix-like place to compile native Windows applications: one would generally not build new applications based on its runtime environment.

为Windows编译的另一种方法是在Linux上使用MinGW交叉编译器.许多MinGW的核心开发人员都以这种方式工作,可以在Wine或在VM或单独的PC上运行的Windows下测试他们的产品.

Another approach to compiling for Windows is to use the MinGW cross compiler on linux. A number of MinGW's core developers work that way, testing they product either under Wine, or under Windows running in a VM or a separate PC.

如果程序具有GUI组件,则可能会有其他困难.一些GUI框架可用于Linux和Windows. Qt wxWidgets IUP 都让人想到,但是还有其他在那里.

If the program has a GUI component, then you may have additional difficulties. Some GUI frameworks are available for both Linux and Windows. Qt, wxWidgets, and IUP all leap to mind, but there are others out there.

编辑:我对上面有关MSYS的段落进行了改进,以强调它旨在作为编译时环境来构建作为本机Windows应用程序运行的程序,而不是完整的POSIX环境.像Cygwin.

I've improved the paragraph above about MSYS to emphasize that it is intended to be a compile-time environment for building programs that run as native Windows applications, and not a full POSIX environment like Cygwin.

还请注意,始终可以选择将项目移植到Windows开发的较传统的编译器之一.Open Watcom,Borland编译器和Microsoft都有免费或便宜的版本,尽管经常没有获得开源社区完全满意的许可.

Note, also, that there is always the option of porting the project to one of the more traditional compilers for Windows development. Open Watcom, the Borland compilers, and Microsoft all have free or inexpensive versions, although often enough not under licenses that make the opens source community entirely happy.

这种方法可能需要更多的精力,因为当您从一个工具链切换到另一个工具链时,Linux环境和Windows环境之间的差异也会变得更加明显.对于历来不像GCC那样完全符合标准的Microsoft编译器来说尤其如此.

This approach probably requires more effort because the differences between a Linux environment and the Windows environment become more visible when you also switch from one toolchain to another. This is especially true of the Microsoft compilers which are historically not as fully standards compliant as GCC.

这篇关于在Windows上运行用Linux编写的C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆