`

mingw和cgywin的gcc编译器区别

阅读更多

In general C codes written in Unix can’t be compiled in Windows OS. Unix has some special system calls(like fork, spawn, signals, select, sockets and so on) which Windows doesn’t has, but Windows has other APIs with same function in that these two kinds of OS all  comply with ANSI C standard. So, fork can’t be called in Windows but Windows usesCreateProcess to accomplish the same function.

MinGW and Cygwin supply two types of C compiler to realize that programmers can code Unix C in Windows environment.
1. MinGW gcc compiler converts Unix calls to Windows APIs in equivalent in the progress of compile.
2.Cygwin gcc compiler is same to the gcc in Unix, for the purpose, it adds one filecygwin1.dll to each application to translate Unix system calls to Win APIs at runtime. Consequently, codes can be run in two OS seamlessly.

Now we can see that Cygwin would be better if your codes ran in Unix but developed in Windows. On the ohter hand, MinGW can compile a pure Win32 application from your Unix codes. Moreover the speed of applications compiled by MinGW is faster than those by Cygwin because the latter has an additional translating process at runtime executed incygwin1.dll

BTW: If you want to get MinGW RAR bag in size of 24MBytes, I’m glad to mail it to you. You can get my email in URl http://blog.classky.com/about/, and please ensure your mailbox could support the size of attachment.  (中文版请点击更多)

    通常情况下Unix下编译通过的C代码在Win32下编译是不能通过的,虽然大多数函数调用在Unix和Win32下是相同的,但是Unix有自己一些独特的系统调用如fork,spawn,signals,select,sockets等),如果代码中使用了这些系统调用,在Win32环境下运行的时候自然是找不到对应的库的。Windows提供的程序接口叫API(其实就是系统调用),它虽然函数名字和Unix下的不一样,但功能确是一样的。如Unix下的fork在Windows中对应的API就是CreateProcess.

     所以如果你想在Windows上开发/编译Unix代码,可以有两种方法:
1、让Windows下的C语言编译器在编译期间将Unix代码中的特殊系统调用转换成相应的Windows API形式,MinGW就是这么做的。
2、编译器还是用Unix的编译器,在每个程序运行期间,当他要执行Unix系统调用时,由一个额外的动态链接库(这是Windows特有的东西,说白了就是一组函数库,在程序运行期间可以动态加载和卸载)将它翻译成Windows API,这就是Cygwin的做法,这个DLL就是cygwin1.dll。

    由些可见,MinGW相比Cygwin来讲更加贴近win32,因为它几乎支持所有的Win32API。它所连接的程序,不需要任何第三方库即可运行,速度较快。但Cygwin编译出来的C代码就等同于Unix环境下编译出来的,所以可以不经修改直接运行在Unix平台,如果要在Windows上运行,加载一个cygwin1.dll就可以了,虽然速度上有点影响,但是实现了跨平台的代码开发。具体选用哪一个,就看各自的需要了。当然如果你只要开发Windows应用程序的话,就要费神想这么多了,VC、BC等都是现成的编译平台。 

参考http://www.livinchina.info/2008/11/27/difference-of-gcc-compiler-between-mingw-and-cygwin/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics