[Cross Compile]cygwin and MinGW

Source: Internet
Author: User
Tags wxwidgets

The C code compiled under UNIX is not possible under Win32, and of course UNIX and Win32 APIs are compliant with standard C, that is, most function calls are identical under UNIX and Win32. However, UNIX has its own unique API (such as fork, Spawn,signals,select,sockets, etc.), if these APIs are used in the code, the corresponding libraries are not found under Win32.
However, the functionality of these APIs can also be implemented in Win32, and you may have discovered a way for Windows to compile UNIX-style code:
1. Modify the compiler so that the compiler under window translates calls such as fork into equivalent form-this is MinGW's approach.
2. Modify the Library so that window provides a Unix-like library that interfaces to programs like UNIX, and these libraries, of course, are implemented by the Win32 API-this is Cygwin's approach.


MinGW compared to CYGWIN/GCC, more close to Win32. Because it almost supports all the WIN32API. It is connected to a program that does not require any third-party libraries to run.
CYGWIN/GCC, this is actually two things. Cygwin is a software that lets windows have a unix-like environment. And GCC is the compiler installed on the Cygwin.
The biggest difference between CYGWIN/GCC and MinGW is that using CYGWIN/GCC can be used to downgrade the Unix-like API in Windows (such as fork,spawn,signals,select,sockets, etc.). This means that Cygwin is running under windows, but she uses the functions and ideas of the unix-like system. Because of this difference, the result is that the program compiled with CYGWIN/GCC can run seamlessly in the *nix environment. However, if you call the UNIX-specific API functions that do not work in a Windows environment, you must rely on cygwin1.dll if you want to work properly under Windows, with some impact on speed.
And the program compiled with MinGW, if the source code calls the UNIX environment API, then MINGW will translate these API calls to UNIX into Win32 equivalent form. At the same time, this program is not running under Windows.
Frankly speaking, if you want to develop Linux running program in Windows environment, then CYGWIN/GCC is your choice.
And if you want to develop a Windows runtime program and pursue speed, then MinGW is a better choice than that.


I have not used these two tools, just a little to choose one to use, so in the online comparison of the two what is different, and then choose a suitable for their own. In the process, I found that an article on the Internet may be reproduced by more than one person, slightly modified by many people as their own essays written, mistakenly recognized.
Say a little, what Cygwin compiled programs can run seamlessly on Linux, simply can't understand.

One of Cygwin's official definitions is that Cygwin is not a-means-to-run native Linux apps on Windows. Rebuild your application from source if you want it to run on Windows.

It's just a translation.
Cygwin is not a way for Linux programs to run on Windows, and if you want Linux programs to run on Windows, you can only recompile the source files with Cygwin.
This statement completely contradicts the idea of running seamlessly on Linux. That is, you compile the ELF program on Linux can not directly get to Cygwin run, similarly, you use Cygwin compiled program is not the Linux elf format, but exe format, EXE can not run on Linux.

Both Cygwin and MinGW provide a way for users to use the GNU tools on the Windows operating system, making it possible to compile C source code written to Linux on Windows and run it (so that you can use the APIs like signal and so on). The real difference is
1,cygwin Big, MinGW small
2,cygwin compiled EXE needs cygwin1.dll as support, and mingw do not need to be able to run directly, because there is a middle layer so cygwin slow, mingw fast.
3,cygwin contains more comprehensive content, can compile through the Linux source files more, MinGW min is minimalist so can compile through less. But, not all, that's to say don't expect you to compile and run any source code written for Linux in Cygwin or MinGW.

What is Cygwin?

Cygwin is a linux-like environment for Windows. It consists of the parts:a DLL (cygwin1.dll) which acts as A Linux API emulation layer providing substantial Linux API Fu Nctionality.

A collection of tools which provide Linux look and feel.

The Cygwin DLL currently works with all recent, commercially released x86 the-bit and the-bit versions of Windows, with the exception of Windows CE.

Note that the official support for Windows, Windows 98, and Windows Me'll be discontinued with the next major version (1.7.0) of Cygwin.


What Isn ' t Cygwin?


Cygwin is not a-to-run native Linux apps on Windows. Rebuild your application from source if you want it to run on Windows.

Cygwin is a-a-magically make native Windows apps aware of UNIX? functionality, like signals, ptys, etc. Again, you need to build your apps from source if you want to take advantage of Cygwin functionality.


Mingw:a collection of freely available and freely distributable Windows specific header files and import libraries Combin Ed with GNU Toolsets-allow one to produce native Windows programs, that does not rely on any 3rd-party C runtime DLLs.

MinGW: As I understand it, it's a compiler under Windows (actually a series of development tools). Unlike other compilers in Windows, MinGW is fully compatible with GNU (basically), which is widely used under Linux, which means that the source code can be compiled under Linux in exactly the same way as in MinGW.

I personally think that the emergence of MinGW for a reason: some Linux developers (such as the Open source camp) release of source code is usually only provided under the Linux compilation method, and does not provide the compilation method under Windows (which may be related to the Windows operating system is not familiar with), But there are a lot of users who need this source code to compile under Windows. In this case, if the Windows users want to use the VC, BC and other compilers to compile the source code, you must rewrite makefile (various compilers support the makefile is not the same), the workload is relatively large, it is difficult to guarantee that there is no error. The advent of MinGW provides a "cross-platform compilation solution" under two platforms. MinGW and Msys together, even./configure. Unlike GNU, MinGW builds an executable (. exe) or library file (. dll,.lib) under Windows-- However, the intermediate files in the compilation process are still the. o file, not the. obj file (which of course doesn't matter, the intermediate file, which is useless after the compilation is complete). MinGW seems to have developed on the basis of Cygwin. By the way Cygwin, it and mingw in the idea of the basic is consistent, compared to the Cygwin is heavyweight (need to download more than 50M up to hundreds of trillion, after installation occupy space up to 1G), MinGW is lightweight (need to download the file only 20M, after installation 70M around), This is purely from the volume, the other Cygwin is now said to be not completely free of charge.

How wxWidgets-2.6.2 is compiled under Windows. VC compiled, there are two ways: VC project, Makefile. The former is needless to say, with VC open *.dsw file, F7 on it can. Here is the way to compile makefile, first go to the Command Line window (cmd.exe or command.exe), switch the path to the wxwidgets source code in the directory under the BUILD/MSW subdirectory, execute "nmake-f makefile.vc". Compile with MinGW, basically similar to the previous, but also into the Command Line window (cmd.exe or command.exe), the switch path to the wxwidgets source code in the directory where the BUILD/MSW subdirectory, just execute the command line is "Mingw32-make- F MAKEFILE.GCC ". The resulting library file is located in the Lib directory. Of course, it may be necessary to set it up before compiling, such as specifying whether to compile to a dynamic library (DLL) or a static library (LIB), or if it is Unicode, and so on, by modifying the CONFIG.VC or CONFIG.GCC files in the BUILD/MSW subdirectory.

Compared to VC6 and MinGW, both are significantly different in terms of compilation speed and size of compiled files. According to the simple statistics I compiled wxwidgets, VC6 compile faster than mingw at least one times, VC6 compiled generated dynamic library DLL file is about one times smaller than MinGW, VC6 compiled static library lib file is much larger than MinGW (about 1.5 times times). The following picture of the compilation of the resulting file size comparison, the left is VC6 generated, the right is MinGW generated, figure one is compiled to generate the dynamic library DLL, figure two is compiled to generate a static library lib file situation:

Always said, in Windows system, or VC compiled more appropriate, no way to choose MinGW.

[Cross Compile]cygwin and MinGW

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.