Linux-原生 C 库:如何配置 Visual Studio 代码以在 Windows 上使用它们?

Linux-native C libraries: How to configure Visual Studio Code to work with them on Windows?

这里完全是菜鸟。

我想在 Windows 机器上使用一些 C 库,例如 unistd.h 和 sys/time.h。我发现很多线程都在讨论是否不使用替代包就根本不可能。但我想知道 Linux 的 Windows 子系统是否随这些库一起提供?如果是这样,我如何配置 Visual Studio 代码与 WSL 一起工作?

But I wonder does the Windows Subsystem for Linux come with those libraries?

是的,WSL 中的编译器将包含这些 headers。

If so, how do I configure Visual Studio Code work with WSL?

您需要在 Windows 功能中启用 WSL,通过 Microsoft Store 安装您喜欢的 linux 发行版,在 VS Code 中安装 "Remote - WSL" 扩展。 可以在此处找到更多信息:https://code.visualstudio.com/docs/remote/wsl

不过请记住,您将在此设置中编译的应用程序将是 linux 个应用程序。他们将只能在 linux 或 WSL 下运行。 您无法使用这些库为 Windows 编译应用程序。这些库依赖于平台。