Mingw, cygwin, and gnuwin32 [cross-platform cross-Compilation of C ++]

Source: Internet
Author: User
Tags tools and utilities

In the past few days, cross-platform compilation in the entire c ++ environment has finally come to an end. The specific content involved is as follows:

First, the three official websites are:
Mingw: http://www.mingw.org
Cygwin: http://www.cygwin.com
Gnuwin32: http://gnuwin32.sourceforge.net

Mingw provides a similar tool set on Windows for those who are used to developing on Linux.
Cygwin is mainly used for LinuxProgram, No changes requiredCodeIt can be transplanted to Windows.
Gnuwin32 is mainly used to Linux tools and provides a set of similar commands on Windows.

C Code Compiled in UNIX cannot be compiled in Win32. Of course, both UNIX and Win32 APIs comply with standard C, that is, most function calls are the same in UNIX and Win32. however, Unix has its own unique APIs (such as fork, spawn, signals, select, and sockets). If these APIs are used in the code, of course, the corresponding library cannot be found under Win32.
However, the functions of these Apis can also be implemented in Win32. You may have discovered a method that allows Windows to compile Unix-style code:
1. Modify the compiler and let the compiler in the window translate fork calls into equivalent forms-this is the mingw practice.
2. modify the library so that window provides a library similar to that provided by Unix. Their interfaces to the program are the same as those of UNIX, of course, it is implemented by Win32 API-this is cygwin's practice.

Cygwin

The project name is from GNU, Cygnus, and windows. Cygwin's goal is to build a Linux Simulation Environment in windows. Therefore, cygwin is a huge project, including not only the development environment in Linux, but also the work environment and various software in Linux.

In the early days, cygwin's core was cygwin1.dll, which can be considered as a POSIX interface implementation. Relying on this dynamic link library, software in Unix/Linux can be easily transplanted to Windows, and the style remains unchanged. However, with the development of cygwin, more and more Unix/Linux programs are porting, and more libraries are dependent on complex programs based on cygwin. Now, after installing cygwin with the default configuration, you will find many dynamic link libraries with Cyg headers.

Currently, cygwin is maintained and supported by RedHat. In terms of copyright, cygwin is not a software, but a system built up by hundreds of thousands of software. It contains components/concepts of commercial software, so its licenses are open-source (GPL) and Commercial (purchased from RedHat.

Mingw

The project name is from the abbreviation of minimalist GNU for Windows.

Initially, mingw was positioned as an open-source development environment in windows. It includes a series of software: Compilation tools, link tools, dump tools, debugging tools, and other development tools. On the other hand, mingw also provides some open-source basic support libraries, such as gnu c/C ++ RT libraries (libc, libstdc ++) and POSIX Basic Call interfaces (including pthread ), there are even interfaces called by OpenGL and Windows APIs. Almost all mingw software is ported from GNU project or Linux to Windows.

Later, mingw had a sub-project called msys, which included more Linux tools. Its goal was to build a Linux Simulation Environment in windows like cygwin.

In short, many things in mingw are complicated, and a considerable part of them are repetitive (currently, mingw has been integrated in the cygwin project ). However, mingw and cygwin have different implementation and design ideas:

    1. Cygwin uses a dynamic link library on the middle layer to connect windows APIs on the lower layer to applications on the upper layer using the POSIX interface. The advantage is that it is more convenient to port applications between Linux and Windows, the style is more consistent; the disadvantage is that cygwin must be included in the dynamic environment library when releasing an application, and the application execution efficiency is slightly lower.

    2. At the basic support database level, mingw uses static links. In this way, the generated applications are more localized and the application execution efficiency is slightly higher. Therefore, mingw declares that applications developed based on mingw do not need to rely on any third-party C/C ++ RT dynamic link library, but only rely on the Windows operating environment:

      Mingw provides a complete open source programming tool set which is suitable for the development of native MS-Windows applications, and which do not depend on any 3rd-party C-runtime DLLs.

However, the conclusion above is not absolute, for example:

    • When you use mingw gcc-MthreadsWhen this option is related to thread-safe Exception Handling, It is dynamically linked to mingwm10.dll.

    • And if you use the mingw GCC 4.4.0 default option to compile the C ++ program, it will dynamically link to the libgcc_s_dw2-1.dll, refer to the following:

      Dynamic LinkingLibgcc_s_dw2-1.dllIs necessary to throw tions between different modules, such as between two DLLs or a DLL and an EXE. consequently, it is the default for all ages other than C. to disable this dynamic linking, use-Static-libgcc. To enable this dynamic linking in C, use-Shared-libgcc.

Mingw POSIX interface is far less comprehensive than cygwin implementation (for example, BSD/Linux socket is not available, and Winsock can only be used). Therefore, it seems that mingw is only a tool set used to develop Windows applications.

In terms of copyright, mingw is more open than cygwin.

After using msys and cygwin, I found that compared with cygwin, msys has many shortcomings:

    1. Tools in msys are more like Unix/Linux tools that are ported to Windows. Some tools support some features of Windows (for example, "\" for directory separation "\"), some are not as useful as the original versions in Unix/Linux (such as Bash and SED ). Cygwin strives to build a Windows environment that fully references the Unix/Linux experience.

    2. Tools in msys are complex and intertwined with tools in mingw (sometimes, the boundaries between development tools and utilities are not very clear, and often need to be used together). The organization is very loose, some enthusiasts provide their own software packages. In this way, building a msys-based Unix/Linux environment becomes a little cumbersome, and you need to be more careful about the dependencies of software packages. When cygwin is used, the installation program will classify and display the organization of the software package, and help you solve the dependency of the software package to a certain extent.

We recommend that you set up a Unix/Linux development environment in windows in this way:

    1. Cygwin's Unix/Linux operating environment, such as Bash, tar, awk, sed, OD, and man.

    2. Use mingw C/C ++ development tools, such as binutils, GCC, GDB, make, and strip. Use mingw basic support libraries, such: the basic call interfaces of GNU libc, libstdc ++, and POSIX.

    3. Use additional support/development libraries as needed, such as pthread, OpenSSL, libiconv, gettext, boost, and wxWidgets.

Note:

    1. Some support/development libraries can be found in the SourceForge of the mingw project, such as pthread (included in the mingw gcc-4.4), OpenSSL, libiconv, gettext and so on. You can also download them from the official project addresses of these libraries or from other Windows transplant project addresses. In short, the links between them are loose.

    2. If some programs are repeated after mingw and cygwin are installed, you can use various techniques to set their priorities, such as setting the search directory order in the path environment variable, create Symbolic Links.

    3. Get the latest mingw. Make it:
      Http://www.profv.de/mingw_cross_env/#tutorial
      Generally, make GCC is OK.

 

Mingw is a Win32 optimized version of the GCC compiler. In theory, mingw can mark C/C ++/FORTRAN /... the original zookeeper program is a Win32 native program, but it is still insufficient to actually migrate the optical transceiver, because many existing datasets only use the Unix-like runtime environment to compile makefile or autotools configuration scripts, therefore, it is necessary to set up the Linux function most commonly used by the program. This is the origin of msys.

Msys just opened a convenient tool for the zookeeper Program, which provides a lot of Linux tools, in addition, it modulo the Linux Command Interpreter and the object architecture. This is very different from cygwin before mingw. cygwin's goal is to compile Linux as a full model on Windows. In fact, cygwin is regarded as an independent target platform that is neither windows nor Linux.

Http://stackoverflow.com/questions/771756/what-is-the-difference-between-cygwin-and-mingw

 

Http://hi.baidu.com/opaquefog/blog/item/f3294f9095982e82a977a4b7.html

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.