Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

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?

question from:https://stackoverflow.com/questions/187990/why-does-gcc-windows-depend-on-cygwin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...