Cygwin
Cygwin, formerly from Cygnus (acquired by Red Hat), is currently a project under the RedHat name. The purpose of the project is to provide a Unix-like environment (represented by GNU tools) running on a Windows platform. To achieve this, Cygwin provides a set of abstraction layer dlls that convert some of the Posix calls into Windows API calls and implement the relevant functionality. The most typical and basic emulation layer is cygwin1.dll. In addition, as Linux systems have grown, Cygwin now offers more than just POSIX compatibility, and therefore has more emulation layer dependencies along with it. BSD, and other Unix systems) to Windows by recompiling them.
Cygnus first took development tools such as gcc, gdb, and gas and improved them so that they could generate and interpret win32 target files. Then, they wanted to port these tools to the windows platform. One option was to make significant changes to the source code of these tools based on the win32 api, which obviously required a lot of work. Therefore, they took a different approach and wrote a shared library (the cygwin dll) that encapsulates unix-style calls (such as fork, spawn, signals, select, sockets, etc.) that are not available in the win32 api, i.e., they wrote a unix system library emulation layer based on the win32 api. Thus, by linking the source code of these tools to this shared library, a cross-compiler on the unix host can be used to generate a toolset that can run on the windows platform. Based on the development tools ported to windows, cygnus gradually ported other tools (which required little modification to the source code, only to their configuration scripts) to windows. In this way, running bash, development tools and user tools on a windows platform feels like working on unix.
Cygwin’s directory structure is basically a copy of linux, but at the same time, it is compatible with many of the features of Windows: most of the applications use Unix-style paths, and Windows discs are provided to Cygwin in a way similar to mount points; Cygwin can run both Cygwin applications (which rely on the emulation layer) and Windows applications, and the paths passed to the applications are transformed by its emulation layer to ensure that the programs run without errors.
Since its emulation layer achieves a fairly good Posix compatibility, people have tried to port many important Linux/BSD applications to Cygwin, making Cygwin bigger and richer, so much so that many people nowadays give Cygwin the task of porting Linux applications directly to the Windows platform (of course, this porting is not native).
Cygwin is a POSIX “subsystem” running on the Windows platform, providing a Unix-like environment for Windows and a development environment for “porting” some Linux applications to the Windows platform. One of the official definitions of cygwin is that Cygwin is not a way to run native linux apps on Windows. You have to rebuild your application from source if you want it to run on Windows. cygwin is not a way to run native linux apps on windows. if you want linux apps to run on windows, then you have to rebuild your application from source with cygwin. This statement completely refutes the claim that it runs seamlessly on linux. It means that the elf program you compile on linux can’t directly get cygwin to run on it, and likewise, the program you compile with cygwin is not in linux elf format, but in exe format, and exe is not able to run on linux.
MinGW
MinGW, Minimalist GNU for Windows, a development environment for developing native (32-bit) Windows applications. It mainly provides tools such as GCC and GNU binutils for win32 applications, as well as header files for the equivalent of the Windows SDK (a subset of) and library files (so, a, etc., rather than the VC lib) for the MinGW version linker.
At the base level, MinGW is a set of include files and port libraries that function to allow console mode programs to use the Microsoft standard C runtime library (MSVCRT.DLL), which is available on all NT OS and on all Windows OS from the Windows 95 release onwards, using the base runtime you can use GCC to write console mode The American Standardization Organization (ANSI) compliant programs can use the C runtime extensions provided by Microsoft. This feature is not available with the Windows32 API. The next component is the w32api package, which is a set of include files and port libraries that can be used with the Windows32 API. Combined with the base runtime, this gives full access to both CRT (C Runtime) and Windows32 API functionality.
MinGW can be used instead of cl to compile WinSDK-based Windows applications that do not include MFC, and the compiled applications do not depend on third-party emulation layer support and run at msvcrt (hence the name native Windows applications), which comes standard with most Windows. In addition, MinGW also supports other languages supported by GCC. For these reasons, MinGW has been chosen as the default compiler for Windows versions by many development tools developed on Linux, such as Code:Blocks and, for example, Dev C++.
MinGW was developed from Cygwin (version 1.3.3).
MinGW, as mentioned earlier, was developed for 32-bit Windows applications. MinGW-W64 is the new generation of MinGW, which supports more APIs, 64-bit application development, and even 32-bit host compilation of 64-bit applications and the reverse “cross-compilation”. In addition, it has different versions for 32-bit and 64-bit, otherwise it is the same as MinGW.
MSys
The full name of MSYS is Minimal SYStem, a subsystem of MinGW, Unix-like command line utilities, a set of bash running on Windows, including the basic bash, make, gawk and grep, etc. It is also a Linux Terminal running on Win. it can also be considered as a small UNIX on Windows. it provides a Unix-like environment on windows to use MinGW. this is better understood, in fact, is to use the Linux command line on Win to operate, you can use instead of cmd. For some GNU open source software, MSYS may be necessary, as they usually require . /configure and then make to run.
To compile a large program, it is not enough to rely on a GCC, but also need to have tools such as Autoconf to configure the project, so generally compile ffmpeg under Windows and other large projects under Linux are done through Msys, of course Msys is only a secondary environment, the fundamental work or MingW to do.
Unlike Cygwin, which is large and comprehensive, MSYS is designed to be small and compact, so the whole set of MSYS and MinGW is mainly basic Linux tools, with a size of about 200M and not much expansion capability. It provides some Unix tools to make MinGW’s tools easier to use. If you don’t like the huge Cygwin and don’t use it much, you can try it. However, if you like the full experience, don’t care about disk footprint, etc., Cygwin is recommended over MSYS.
Since MinGW has not been updated for years, and MSYS even more so, many of Cygwin’s new features have not been synchronized with MSYS, so Alex and others have created a new generation of the MSYS project. It still forked Cygwin (a newer version), but has a much better package manager, pacman, an active developer and user group, and a large number of pre-compiled packages (though certainly not as many as Cygwin) …… For those who don’t like the huge Cygwin, we recommend trying msys2 .
MSYS2 (Minimal SYStem 2) is a standalone rewrite of MSYS, mainly for shell command line development environments. It is also a Windows software that builds on Cygwin (POSIX compatibility layer) and MinGW-w64 (from “MinGW-generation”) for better interoperability. MSYS2 is an upgraded version of MSYS, to be exact, it is an upgraded version of Cygwin which integrates pacman and MinGW-w64, providing linux environment such as bash shell, version control software (git/hg) and MinGW-w64 tool chain. The biggest difference with MSYS is the porting of Pacman, the package management system of Arch Linux (which is actually the difference with Cygwin).
Cygwin, MinGW, MSys Comparison
Features | Cygwin | MinGW/MSYS | MSYS2 |
---|---|---|---|
Is GNU | No | Yes | Yes |
More software support? | Support most GNU software | Support common software, git, Vim and other software need to be supported independently (see below for details) | Support most GNU software |
More Linux-like | Cygwin in Windows is like Wine in Linux | Implementation of major Linux programs such as Bash | Native 64/32bit support |
GCC compilation | includes MingGW32 cross-compilation, which supports both cygwin1.dll dependent programs and standalone Windows programs; you can compile Linux applications directly | support standalone Windows programs | support standalone Windows programs |
Chinese support | direct support for Chinese display and input method | need to configure to support Chinese display and input, delete a Chinese character need to delete 2 times | support Chinese display and input method, Chinese help system and Chinese prompt (some software) |
Running speed | slow | fast | fast |
The C code compiled under Unix cannot be compiled under Win32. The APIs of Unix and Win32 are in line with standard C, and most function calls are the same under Unix and Win32. However, unix has some unique APIs (such as fork, spawn, signals, select, sockets, etc.) If these APIs are used in the code, the corresponding libraries cannot be found under win32.
Summary of the difference.
- Modify the compiler so that the compiler under window translates calls such as fork into equivalent forms, which is what mingw does.
- Modify the library so that window provides a library similar to the one provided by unix, and they interface to the program as if it were unix, and these libraries are of course implemented by the win32 API, which is what cygwin does.
MingW and cygwin are not able to make Linux programs run directly on Windows, they must be recompiled through the source code. The main differences in their specific implementations of these functions are.
- The format of executable files, Window uses PE format and requires .EXE suffix, Linux uses Elf.
- The APIs of the operating systems are also different, e.g. Windows uses CreateProcess() to create processes, while Linux uses fork()
cygwin/gcc can be completely equivalent to gcc under linux, which can be seen from the division of boost library, gcc under cygwin and gcc under linux use exactly the same Toolsets. so it is possible to update gcc version together with linux without worrying about problems, and in The stuff made in cygwin/gcc (without using win32) can be used under linux seamlessly without any problem. It is a good choice for developing linux programs under windows. However, the program compiled under cygwin/gcc must depend on cygwin1.dll for windows execution, and it is a bit slow, so if you don’t want to depend on this, you must add -mno-cygwin to the compilation options of gcc. Minw, which is a cross-compilation of gcc.
MinGW is closer to Win32 than CygWin/gcc, because it supports almost all Win32 APIs, and the programs it connects to can run without any third-party libraries. And gcc is the compiler that is installed on CygWin.
The programs generated by both are EXE files that run on Windows, both in PE format, and a PE format checker will show that the programs generated by Cygwin still have Linux system calls like fork(), but the target library is cygwin1. So it seems that compiling with Mingw will give a higher performance and you don’t have to carry around the cygwin1.dll file which is close to two megabytes. However, Cygwin has a more complete emulation of Linux, and there is even a Cygwin X project that allows you to run X directly with Cygwin. in addition Cygwin can set the -mno-cygwin flag to use Mingw compilation. The tools on MSys, which are more comparable to Cygwin, are also provided through Cygwin in this emulation.
Cygwin, MinGW, MSys How to choose?
If developing linux programs on windows, cygwin is a good choice. Cygwin is also the choice if you develop programs that don’t mind having a cygwin1.dll. If you want to develop programs for windows and have to use gcc, mingw is a good choice. To sum up, it is more appropriate to compile with VC under Windows, and MinGW is the only choice when there is no other way.
WSL
The WSL, known as Windows Subsystem for Linux, is a compatibility layer for being able to run Linux binary executables natively on Windows 10 ( ELF format) compatibility layer on Windows 10.
What does Windows Subsystem for Linux do? How is it different from a virtual machine?
Compared to virtual machines, Windows Subsystem for Linux has the following advantages.
- Better performance. Performance is much better than a virtual machine because the implementation is more under the hood.
- Shared file system with Windows. The subsystem is able to access all the files on the hard disk directly, and can even execute .exe files.
Summary: WSL is the ultimate solution.