From a technical POV, what does MinGW make gcc possible for windows?

A few questions:

  • Is it right to understand that MinGW essentially takes the gcc source and compiles it into an executable for windows, i.e. gcc.exe?

  • The MinGW wiki says: "MinGW, on the other hand, provides the functions provided by the Win32 API." It bothers me. Doesn't the default Windows installation already provide the Win32 API headers that provide the Win32 API, which would make MinGW superfluous? Are MinGW headers different from those that come with a Windows installation?

  • When I have an object file compiled by MinGW gcc, can I just link it to the C runtime library on windows? I think not because the object file created by MinGW gcc may not be compatible (for example, using the same calling conventions) as the C runtime library in windows.

+6
source share
2 answers
  • What do you mean by "gcc source"? When you say "gcc source", you can mean "GCC compiler source code." MinGW is a version of Windows GCC, so it takes any C source code and creates executable files, and it is GCC, so it has the functions of this compiler.

  • I think the header files provided by Microsoft (e.g. windows.h and winusb.h) are not really compatible with GCC. The MinGW project includes GCC compatible header files, so you can call Windows functions such as ReadFile from your program. The last time I checked, MinGW had only some Microsoft header files; he was absent winusb.h.

  • Why do you want to link to the Windows Runtime Library? I know that cross-compiler is possible because I once wrote a DLL with a Microsoft C compiler and called it from MinGW (Qt).

+2
source
  • GCC is a multi-platform compiler, so there is a Linux version, a MacOS version, a Windows version of this compiler. "MinGW GCC" is one of two existing versions of Windows. The "MinGW system" is nothing more than a set of Windows versions of some GNU tools.

  • I just read the MinGW Wiki entry, and the “provided by Win32 API” seems to clarify the difference between “Cygwin” and “MinGW” - not between “MinGW” and the Microsoft C compiler:

    Two different versions are available for many GNU Windows tools: Cygwin and MinGW.

    "Cygwin" uses a special emulation environment to emulate a file system like Unix. A special library will be associated with programs in which functions such as "fopen" convert file names in the form "/home/mydir/myfile.txt" to file names such as "c: \ programs \ cygwin \ home \ mydir \ myfile ".. txt".

    Using the "Cygwin" compiler, both on the "gcc" command line and on the command lines of the programs created (more precisely: related), a Unix file name is required.

    However, the MinGW tools behave like other Windows programs and use regular Windows libraries, where functions such as fopen expect normal Windows filenames such as c: \ somedir \ somefile. Programs created by the "MinGW" GCC compiler behave like programs created by the Microsoft compiler.

    Unlike Linux, Windows does NOT come with header files, but they do come with the Win32 API, which must be downloaded (> 1GiB) from Microsoft. MinGW and Cygwin provide some native header files that are almost compatible with Microsoft, so there is no need to download the Win32 API.

  • Most development tools on Windows use the same object and static library file format. (The Watcom compiler is one of the few exceptions.) This means that you can mix object files and static libraries compiled with different compilers. (The format of the .lib / .a libraries that are used to dynamically bind to DLLs is different from gcc and Microsoft, so you cannot mix them!)

About the comment for another answer:

  • MinGW usually refers to "msvcrt.dll" that comes with Windows. This file contains standard C functions such as "printf ()".
  • Microsoft Visual C ++ sometimes refers to msvcrt.dll, sometimes to some DLLs, such as msvcr100.dll. "msvcr100.dll" also contains standard C functions, however some of them have advanced functionality (eg Unicode ...). "msvcr100.dll" must be installed after installation because it does not ship with Windows.
  • Cygwin refers to files such as "cygwin1.dll" containing a version of Cygwin's standard C functions (which differ when processing file names). Needless to say, this file does not ship with Windows, but must be installed after installation.

Unlike "libc" on Linux, all these DLLs do not directly call the operating system, but they call "kernel32.dll", which contains lower-level functions (for example, "WriteFile ()") that call the operating system.

+2
source

Source: https://habr.com/ru/post/972007/


All Articles