Why does GCC-Windows depend on cygwin?

后端 未结 11 1744
陌清茗
陌清茗 2020-12-24 11:21

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,

11条回答
  •  独厮守ぢ
    2020-12-24 12:07

    POSIX (Portable Operating System Interface) "is an evolving, growing document that is being produced by IEEE and standardized by ANSI and ISO. The goal of POSIX is the source-code portability of application" [1].

    In practical terms, the goal is defined as the ability to write one source implementation and have it run on different (POSIX-compliant) systems with only recompilation.

    GCC is a compiler capable of delivering that promise and as such, it needs a layer of code that brings a machine "up to" POSIX standards.

    That is the core of the answer to your question.

    To help see what I mean, I'll offer you this exercise:

    • Write a program with no OS-specific #ifdefs that takes as input from the user some directory path and writes to stdout a listing of its contents (one level).

    I think you will find that it is very difficult to write code that uses only the native WIN32 API that compiles on any UNIX or LINUX system

    It will be only slightly less difficult to write code that uses POSIX API - as you can on any LINUX box - and have it compile under Windows (DevStudio2005 has a surprising number of POSIX-compliant headers now...you might be able to get close).

    Take you LINUX program from above and now compile it under GCC running under Cygwin or MinGW. I'll bet it compiles and runs.

    How did GCC perform that bit of magic? The POSIX headers and implementations underlying them provided by Cygwin or MinGW.

    Does GCC's reliance on Cygwin/MinGW under Windows make more sense now?

    1. POSIX.4: Programming for the Real World, Bill O. Gallmeister, O'Reilly & Associates, Inc., pg 2

提交回复
热议问题