# Cygwin

**Cygwin** 是一组 GNU 及其他开源工具，外加一个运行时库 `cygwin1.dll`，二者共同在 [Microsoft Windows](https://www.edgepedia.org/zh/microsoft-windows) 上提供一个类 Linux 的、兼容 POSIX 的环境。该 DLL 提供了大量 POSIX 系统调用功能，而这些工具则带来 Linux 的外观与体验，使得许多 UNIX 软件只需极少改动甚至无需改动源代码，便可在 Windows 上配置、构建和运行。<sup>[1](https://cygwin.com/cygwin-ug-net/overview.html)</sup><sup> • </sup><sup>[2](https://cygwin.com/doc/preview/faq/faq.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 它是什么 | 一个面向 Windows 的类 Linux 环境：`cygwin1.dll` POSIX 模拟层，加上一大组 GNU 及开源工具<sup>[1](https://cygwin.com/cygwin-ug-net/overview.html)</sup> |
| 起源 | 1995 年在 Cygnus Solutions 开始开发，该公司现属 Red Hat 公司<sup>[3](https://cygwin.com/cygwin-ug-net/brief-history.html)</sup> |
| 当前版本 | Cygwin DLL 3.6.11；可运行于从 Windows 8.1 起的近期商业发布的 x86_64 Windows 版本<sup>[4](https://cygwin.com/)</sup> |
| C 库 | 使用 `newlib` 而非 `glibc`，这是与 Linux 的主要区别<sup>[1](https://cygwin.com/cygwin-ug-net/overview.html)</sup> |
| 包管理 | 自带安装程序，通常称为 setup.exe；各软件包的版本独立于 DLL<sup>[5](https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin/)</sup><sup> • </sup><sup>[4](https://cygwin.com/)</sup> |
| 许可证 | Cygwin DLL 自 2.5.2 版起采用 LGPL 许可证；更早的版本为 GPL<sup>[2](https://cygwin.com/doc/preview/faq/faq.html)</sup> |
| 基础安装体积 | 默认的最小基础安装约占 100 MB<sup>[6](https://cygwin.org/cygwin/install.html)</sup> |

## 目的与架构

Cygwin 的存在，是为了让 UNIX 软件无需大量重写即可在 Windows 上运行。当执行一个链接到该库的二进制文件时，Cygwin DLL 会被加载到应用程序的代码段中。由于该库模拟的是一个需要访问其下所有运行进程的 UNIX 内核，第一个运行的 Cygwin DLL 会创建共享内存区和全局同步对象，供使用该 DLL 其他实例的进程访问；这些结构用于跟踪打开的文件描述符，并辅助 fork 和 exec。每个进程还带有一个进程级结构，其中包含进程 ID、用户 ID 和信号掩码等信息。<sup>[7](https://cygwin.com/cygwin-ug-net/cygwin-ug-net.pdf)</sup>

该 DLL 以 Win32 子系统中的标准 DLL 形式实现，使用 Win32 API，并在适当之处使用原生 NT API，主要是为了速度，以及利用 Win32 API 未暴露、但对 POSIX 特性有用的 NT 能力。在 Cygwin 下运行的程序既可以调用 UNIX 兼容函数，也可以调用 Win32 API，因此开发者可以例如在 UNIX 风格的后端之上编写 Win32 图形界面。<sup>[7](https://cygwin.com/cygwin-ug-net/cygwin-ug-net.pdf)</sup><sup> • </sup><sup>[8](https://usenix.org/legacy/publications/library/proceedings/usenix-nt98/full_papers/noer/noer_html/noer.html)</sup>

该 API 尽可能遵循[单一 UNIX 规范](https://www.edgepedia.org/zh/single-unix-specification)，其次遵循 Linux 惯例。Cygwin 与 Linux 的主要区别在于 C 库：Cygwin 使用 `newlib` 而非 `glibc`。<sup>[1](https://cygwin.com/cygwin-ug-net/overview.html)</sup>

## Cygwin 不是什么

项目自己的主页划出了两条界线。Cygwin 不是一种在 Windows 上运行原生 Linux 二进制文件的方法；应用程序必须从源代码重新构建。它也不是一种让原生 Windows 应用程序感知信号或 pty 等 UNIX 功能的方法；同样，应用程序必须从源代码构建才能使用 Cygwin 的特性。<sup>[4](https://cygwin.com/)</sup>

## 历史

Cygwin 于 1995 年在 Cygnus Solutions 开始开发，该公司成立于 1989 年，旨在为 GNU 开发工具提供商业支持。第一项任务是增强这些工具（gcc、gdb、gas 等），使其能够生成和解释 Microsoft 可移植可执行格式的 Win32 原生目标文件。团队没有针对 Win32 API 重写每个工具，而是编写了一个共享库——Cygwin DLL——来补充 Win32 所缺的类 UNIX 功能，如 `fork`、`spawn`、信号、`select` 和套接字；这一接口被称为 Cygwin API。<sup>[3](https://cygwin.com/cygwin-ug-net/brief-history.html)</sup><sup> • </sup><sup>[8](https://usenix.org/legacy/publications/library/proceedings/usenix-nt98/full_papers/noer/noer_html/noer.html)</sup>

当时供职于 Cygnus Solutions 的 Geoffrey J. Noer 在 1998 年 USENIX [Windows NT](https://www.edgepedia.org/zh/windows-nt) 研讨会论文《Cygwin32: A Free Win32 Porting Layer for UNIX Applications》中描述了早期架构。最初的版本包含除 `setuid` 和 `mkfifo` 之外的所有 POSIX.1/90 调用、所有 [ANSI C](https://www.edgepedia.org/zh/ansi-c) 标准调用，以及许多常见的 BSD 和 SVR4 服务，包括 Berkeley 套接字。Cygnus 以 GNU 通用公共许可证发布该技术，同时也向受支持客户出售商业许可证。<sup>[8](https://usenix.org/legacy/publications/library/proceedings/usenix-nt98/full_papers/noer/noer_html/noer.html)</sup><sup> • </sup><sup>[9](https://www.usenix.org/conference/2nd-usenix-windows-nt-symposium/cygwin32-free-unix-porting-layer-win32)</sup>

自举（即这些工具能在 Windows 下重新构建自身）在 1996 年 10 月的 beta 17.1 版本中实现。2000 年 4 月，项目宣布了新的网络发布版，附带一个图形化的、非 Cygwin 的安装程序，可分别安装和升级每个软件包。2009 年的 1.7 版放弃了对 [Windows 95](https://www.edgepedia.org/zh/windows-95)/98/Me 的支持，转而更广泛地利用 Windows NT 特性，增加了区分大小写的文件名、NFS 互操作和 IPv6 支持。首个提供 64 位版本的发布版是 1.7.19。<sup>[3](https://cygwin.com/cygwin-ug-net/brief-history.html)</sup>

如今该项目由社区运营：Cygwin 最初由 Cygnus Solutions 开发，但大部分软件包维护工作和相当比例的开发工作由非 [Red Hat](https://www.edgepedia.org/zh/red-hat) 的志愿者承担，项目负责人是 Red Hat 高级工程师 Corinna Vinschen。<sup>[10](https://cygwin.com/who.html)</sup>

## 文件系统与路径

由于许多 UNIX 程序假定存在单一的、统一的 POSIX 文件系统树，Cygwin 在内部维护一个 Win32 文件系统的 POSIX 视图，并按需转换路径。`/etc/fstab` 文件将 Win32 驱动器和网络共享映射到这棵 POSIX 树中，既有系统级文件，也可在 `/etc/fstab.d` 中放置可选的每用户文件。未挂载的驱动器可通过内置的 `cygdrive` 前缀访问，例如驱动器 Z: 对应 `/cygdrive/z/`。该 DLL 同时支持 POSIX 风格和 Win32 风格的路径，但不推荐使用 Win32 路径，因为它绕过了内部路径处理。<sup>[11](https://ftp.cygwin.com/cygwin/cygwin-ug-net/using.html)</sup><sup> • </sup><sup>[12](https://cygwin.com/faq.html?external_link=true)</sup>

## fork 与进程创建

`fork` 系统调用与 Win32 API 的契合度不佳，Cygwin 的实现是一种类似于早期 UNIX 系统的非写时复制版本，因此相对较慢；大多数情况下，`spawn` 系列调用更为可取。父进程在 Cygwin 进程表中预留空间，并通过 Windows 的 CreateProcess 调用以挂起状态创建子进程。由于 Windows 不允许删除正在使用的二进制文件，该实现依赖硬链接和 DotLocal DLL 重定向机制，使原文件以其原始名称保持可用；项目文档指出，当前的 Windows 实现使得完全可靠的 fork 不可能实现，偶尔的 fork 失败不可避免。<sup>[12](https://cygwin.com/faq.html?external_link=true)</sup><sup> • </sup><sup>[7](https://cygwin.com/cygwin-ug-net/cygwin-ug-net.pdf)</sup>

## 安装与版本

安装使用 `setup-x86_64.exe` 程序，它执行全新安装和更新，并记住此前的软件包选择。默认只安装最小基础包，约 100 MB；bash、gcc、less 等各个软件包独立于 Cygwin DLL 发布，因此 DLL 版本号不能作为该发行版的通用版本号。<sup>[6](https://cygwin.org/cygwin/install.html)</sup><sup> • </sup><sup>[4](https://cygwin.com/)</sup>

当前 DLL 版本为 3.6.11，可与从 [Windows 8.1](https://www.edgepedia.org/zh/windows-8-1) 起的近期商业发布的 x86_64 Windows 版本配合使用。Cygwin 3.4.10 是最后一个支持 [Windows 7](https://www.edgepedia.org/zh/windows-7)、Windows 8、Windows Server 2008 R2 和 Windows Server 2012 的版本；更旧的系统可通过 Cygwin Time Machine 归档获得支持，例如面向 Windows Vista 和 Server 2008 的 DLL 3.3.6，以及面向 Windows XP SP3 和 Server 2003 的 DLL 2.5.2。<sup>[4](https://cygwin.com/)</sup><sup> • </sup><sup>[6](https://cygwin.org/cygwin/install.html)</sup>

## Cygwin 与 MSYS2、WSL 的比较

**MSYS2** 基于 Cygwin：其类 UNIX 工具直接源自 Cygwin，其运行时库 `msys-2.0.dll` 是 `cygwin1.dll` 的一个变体，改动包括自动改写命令行参数的路径、转换原生 Windows 输出的行尾，以及移除 `/cygdrive` 前缀。两个项目的目标不同：Cygwin 试图为 Windows 带来一个兼容 POSIX 的环境，使大多数 UNIX 软件只需极少修改即可构建和运行；而 MSYS2 侧重于针对 Windows API 构建原生 Windows 软件，仅提供最小的 POSIX 模拟环境。MSYS2 使用 [Arch Linux](https://www.edgepedia.org/zh/arch-linux) 的包管理器 Pacman，而 Cygwin 只附带由其自带安装程序管理的、依赖 Cygwin 的软件。<sup>[5](https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin/)</sup><sup> • </sup><sup>[13](https://www.msys2.org/docs/what-is-msys2/)</sup>

**WSL**，即 [Windows Subsystem for Linux](https://www.edgepedia.org/zh/windows-subsystem-for-linux)，运行真正的 Linux 二进制文件：WSL 2 在轻量级工具虚拟机内运行由 Microsoft 构建的 [Linux 内核](https://www.edgepedia.org/zh/linux-kernel)。Microsoft 自己的移植指南并排列出了这些选项，称 Cygwin 相比 MinGW 或 MinGW-w64 在 Windows 上提供了更完整的 Linux 环境，而 WSL 则原样运行 Linux 程序。Cygwin 方案的一个实际后果是其自有 ABI：Cygwin GCC 生成的二进制文件使用 Cygwin ABI 并依赖 Cygwin DLL，因此，例如 Cygwin 的 Python 无法安装为 Windows MSVC ABI 构建的预编译 wheel 包，pip 必须从源代码构建它们。<sup>[14](https://learn.microsoft.com/en-us/cpp/porting/porting-from-unix-to-win32?view=msvc-170)</sup><sup> • </sup><sup>[15](https://tmewett.com/dev-on-windows/)</sup>

## References

1. [Chapter 1. Cygwin Overview, Cygwin User's Guide](https://cygwin.com/cygwin-ug-net/overview.html)
2. [Cygwin FAQ](https://cygwin.com/doc/preview/faq/faq.html)
3. [A brief history of the Cygwin project, Cygwin User's Guide](https://cygwin.com/cygwin-ug-net/brief-history.html)
4. [Cygwin home page](https://cygwin.com/)
5. [How does MSYS2 differ from Cygwin?, MSYS2 documentation](https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin/)
6. [Installing and Updating Cygwin Packages](https://cygwin.org/cygwin/install.html)
7. [Cygwin User's Guide (PDF)](https://cygwin.com/cygwin-ug-net/cygwin-ug-net.pdf)
8. [Geoffrey J. Noer (1998). Cygwin32: A Free Win32 Porting Layer for UNIX Applications, 2nd USENIX Windows NT Symposium](https://usenix.org/legacy/publications/library/proceedings/usenix-nt98/full_papers/noer/noer_html/noer.html)
9. [Cygwin32: A Free UNIX Porting Layer for Win32, USENIX conference page](https://www.usenix.org/conference/2nd-usenix-windows-nt-symposium/cygwin32-free-unix-porting-layer-win32)
10. [Cygwin Community](https://cygwin.com/who.html)
11. [Chapter 3. Using Cygwin, Cygwin User's Guide](https://ftp.cygwin.com/cygwin/cygwin-ug-net/using.html)
12. [Cygwin FAQ (full)](https://cygwin.com/faq.html?external_link=true)
13. [What is MSYS2?, MSYS2 documentation](https://www.msys2.org/docs/what-is-msys2/)
14. [Running Linux programs on Windows, Microsoft Learn](https://learn.microsoft.com/en-us/cpp/porting/porting-from-unix-to-win32?view=msvc-170)
15. [Tom Mewett, Linux-style CLI dev setup on Windows: comparing native, MinGW, Cygwin, WSL](https://tmewett.com/dev-on-windows/)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs › Mobile and platform frameworks

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/cygwin

English original: https://www.edgepedia.org/cygwin
