Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does GCC-Windows depend on cygwin?

I'm not a C++ developer, but I've always been interested in compilers, and I'm interested in tinkering with some of the GCC stuff (particularly LLVM).

On Windows, GCC requires a POSIX-emulation layer (cygwin or MinGW) to run correctly.

Why is that?

I use lots of other software, written in C++ and cross-compiled for different platforms (Subversion, Firefox, Apache, MySQL), and none of them require cygwin or MinGW.

My understanding about C++ best-practice programming is that you can write reasonably platform-neutral code and deal with all the differences during the compilation process.

So what's the deal with GCC? Why can't it run natively on Windows?


EDIT:

Okay, the two replies so far say, basically, "GCC uses the posix layer because it uses the posix headers".

But that doesn't really answer the question.

Let's say I already have a set of headers for my favorite standard library. Why would I still need the posix headers?

Does GCC require cygwin/mingw to actually RUN?

Or does it only need the emulation layer for headers and libraries? If so, why can't I just give it a "lib" directory with the required resources?


EDIT AGAIN:

Okay, I'll try again to clarify the question...

I also write code in the D Programming Language. The official compiler is named "dmd" and there are official compiler binaries for both Windows and linux.

The Windows version doesn't require any kind of POSIX emulation. And the Linux version doesn't require any kind of Win32 emulation. If the compiler has assumptions about its environment, it hides those assumptions pretty well.

Of course, I have to tell the compiler where to find the standard library and where to find libraries to statically or dynamically link against.

GCC, by contrast, insists on pretending it's operating within a posix environment, and it asks ME to humor those assumptions by setting up an emulation layer.

But what, exactly, within GCC relies on that layer? Is it just looking for stdlib headers, and it assumes it'll find those headers within "/usr/lib"?

If that's the case, shouldn't I just be able to tell it to look in "C:/gcc/lib" to find those header files?

Or does GCC itself rely on the POSIX libraries to access the file system (and to do other low-level stuff)? If that's the case, then I wonder why they don't just statically link with their favorite windows POSIX libraries. Why require the user to set up the dependencies, when they could build those dependencies right into the application?

like image 711
benjismith Avatar asked Oct 09 '08 16:10

benjismith


People also ask

Does Cygwin have GCC?

By default, the new version of GCC will be installed to /usr/local in Cygwin's virtual filesystem.

How do I know if GCC is installed in Cygwin?

Once setup is finished, run Cygwin again, and type "g++ -v" to confirm the GCC C++ compiler is installed. This should come up with some version information text. You can also access the compiler from the Windows Command line ("DOS Screen").

What compiler does Cygwin use?

mingw64-x86_64-gcc-g++ : 64-bit C++ compiler for native 64-bit Windows. The executable is " x86_64-w64-mingw32-g++ ".


2 Answers

Actually, the question premise is wrong: MinGW GCC does NOT require Cygwin.

You will see you don't need Cygwin at all. It runs natively on Windows (32-bit, at least). Both the toolchain and the produced binaries are independent of Cygwin.

The MinGW compilers available in Cygwin are different: they are built on the Cygwin platform, to generate code which does not depend on the Cygwin runtime. The compilers themselves do depend on Cygwin in that case. But that's because you installed them from Cygwin.

like image 121
David Cournapeau Avatar answered Sep 18 '22 20:09

David Cournapeau


The Cygwin version of GCC requires Cygwin to be installed, for programs it compiles.

The MinGW version does not require anything after compiling, other than a working copy of Windows.

You can't really mix the Cygwin environment, and the MinGW compilers together, because Cygwin changes the paths of the precompiled libraries.

If you need a bash style shell, but don't want to use Cygwin, I would recommend MSYS.

Cygwin in contrast to MinGW

copied from MinGW Wiki

Cygwin applications by principle are not considered a "Native Win32 application" because it relies on the Cygwin® POSIX Emulation DLL or cygwin1.dll for Posix functions and does not use win32 functions directly. MinGW on the other hand, provides functions supplied by the Win32 API. While porting applications under MinGW, functions not native to Win32 such as fork(), mmap() or ioctl() will need to be reimplemented into Win32 equivalents for the application to function properly.
like image 24
Brad Gilbert Avatar answered Sep 20 '22 20:09

Brad Gilbert