Several questions:
Is it correct to understand that MinGW is essentially taking the gcc source and compiling it into an executable for windows, i.e gcc.exe?
MinGW wiki says "MinGW on the other hand, provides functions supplied by the Win32 API.". This confuses me. Doesn't a Windows installation by default already provide the Win32 API headers that exposes the Win32 API, which would make MinGW providing it again redundant? Are the headers MinGW provides different to the ones 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'd think not because the object file generated by MinGW gcc may not be compatible(like uses the same calling conventions) as the C runtime library on windows.
What do you mean by "gcc source"? When you say "gcc source" you might mean "the source code of the GCC compiler". MinGW is a windows version of GCC, so it takes any C source code and produces executables, and it is GCC so it has the features of that compiler.
I think the header files provided by Microsoft (e.g. windows.h and winusb.h) are not actually compatible with GCC. The MinGW project includes header files that are compatible with GCC so you can call Windows functions like ReadFile
from your program. The last time I checked, MinGW only had some of the Microsoft header files; it was missing winusb.h.
Why do you want to link with a Windows runtime library? I know that cross-compiler interop is possible because I once wrote a DLL with the Microsoft C compiler and called it from a MinGW (Qt) program.
GCC is a multi-platform compiler so there is a Linux version, a MacOS version, a Windows version of this compiler. The "MinGW GCC" is one of at least two Windows versions existing. The "MinGW system" is nothing but a collection of the Windows versions of some GNU tools.
I just read the MinGW Wiki entry and the "supplied by the Win32 API" seems to clarify the difference between "Cygwin" and "MinGW" - not between "MinGW" and the Microsoft C compiler:
For many GNU tools there are two different versions available for Windows: "Cygwin" and "MinGW".
"Cygwin" uses a special emulation environment to emulate a Unix-like file system. A special library will be linked to the programs where functions like "fopen" will convert file names in the form "/home/mydir/myfile.txt" to file names like "c:\programs\cygwin\home\mydir\myfile.txt".
Using the "Cygwin" compiler both the "gcc" command line and the command lines of the programs created (more exact: linked) by it require Unix-like file names.
The "MinGW" tools however behave like other Windows programs and use the normal Windows libraries where functions like "fopen" expect "normal" Windows-like file names like "c:\somedir\somefile". Programs built by the "MinGW" GCC compiler behave like programs built by the Microsoft compiler.
Unlike Linux Windows does NOT come with any header files but they come with the Win32 API that has to be downloaded (> 1GiB) from Microsoft. MinGW and Cygwin provide some own header files that are nearly compatible with the Microsoft ones so it is not necessary to download the Win32 API.
Most development tools in Windows use the same object and static library file format. (The "Watcom" compiler is one of the few exceptions.) This means you can mix object and static library files compiled with different compilers. (The format of .lib/.a stub libraries used for dynamic linking against DLLs differs between gcc and Microsoft so you cannot mix them!)
About the comment to the other answer:
Unlike "libc" in Linux all of these DLLs do not directly call the operating system but they call "kernel32.dll" which contains lower-level functions (like "WriteFile()") that will call the operating system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With