C语言 Visual Studio 2010 的替代 unistd.h 头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6365058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 08:56:00  来源:igfitidea点击:

Alternative unistd.h header file for Visual Studio 2010

cvisual-studio-2010

提问by thetna

I am compiling the code in Visual Studio 2010which includes header file unistd.h. Since windows does not have any support for the header file unistd.h, I am looking for the alternative header file or is there any way to customize it so that I can compile it in Visual Studio as well.

我正在编译Visual Studio 2010包含头文件的代码unistd.h。由于 windows 不支持头文件unistd.h,我正在寻找替代头文件,或者有什么方法可以自定义它,以便我也可以在 Visual Studio 中编译它。

回答by Richard

Try include io.h, it's equivalent of unistd.h in MSVC. if you want to maintain the compatibility, try this:

尝试包含 io.h,它相当于 MSVC 中的 unistd.h。如果你想保持兼容性,试试这个:

#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

回答by paxdiablo

Your best bet, rather than trying to fit an inappropriate header file into Windows, is simply to remove the line:

最好的办法,而不是尝试将不适当的头文件放入 Windows,只需删除该行:

#include <unistd.h>

then try and compile your code.

然后尝试编译您的代码。

You may find (if you're extremelylucky) that it uses no features of that at all.

您可能会发现(如果您非常幸运的话)它根本没有使用任何功能。

However, more likely is that there are certain things that it will use from that header and any associated libraries, and you will need to either implement these or find a Windows equivalent.

但是,更有可能的是,它会从该头文件和任何关联的库中使用某些内容,您将需要实现这些内容或找到 Windows 等效项。

If you wanted to keep the code as portable as possible, I would create a WindowsUniStd.h file (and an associated source file) to implement the bare minimum needed by the program.

如果您想尽可能保持代码的可移植性,我将创建一个 WindowsUniStd.h 文件(和一个关联的源文件)来实现程序所需的最低限度。

回答by thiton

If you need a minimal GNU environment for windows with some of the functionality of unistd.h, you would look to the MinGW projectfirst. If you're lucky, you can get away without using their compiled libraries at all.

如果您需要具有 某些功能的最小 GNU 环境unistd.h,您可以首先查看MinGW 项目。如果幸运的话,您可以完全不使用他们编译的库。

If that isn't enough, you are into porting a program, and you are porting onto the bad system. Windows is computational backwater, providing a full unistd.h is a Herculean task, and you're probably better of either rewriting the application to remove references to unistd.h or using Cygwin.

如果这还不够,那么您正在移植一个程序,并且您正在移植到坏系统上。Windows 是计算上的死水,提供完整的 unistd.h 是一项艰巨的任务,您最好重写应用程序以删除对 unistd.h 的引用或使用 Cygwin。