I am compiling the code in Visual Studio 2010
which 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.

- 6,903
- 26
- 79
- 113
-
1google "unistd.h windows" and go "I feel lucky" 2nd match is a SO question about exactly the same thing you are asking... – Fredrik Pihl Jun 15 '11 at 22:20
-
1possible duplicate of [is there a replacement for unistd.h for Windows (Visual C)?](http://stackoverflow.com/questions/341817/is-there-a-replacement-for-unistd-h-for-windows-visual-c) – Frerich Raabe Jun 15 '11 at 22:45
-
Does the solution mentioned is for general case ? I don't have much idea on these stuff. Can you please elaborate, what are the things I need to keep in mind to create a new header file ? – thetna Jun 15 '11 at 22:59
-
There is approved answer here: http://stackoverflow.com/questions/341817/is-there-a-replacement-for-unistd-h-for-windows-visual-c – Stan Huang at Taiwan Mar 31 '16 at 01:37
3 Answers
Try include io.h, it's equivalent of unistd.h in MSVC. if you want to maintain the compatibility, try this:
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

- 139
- 1
- 8
Your best bet, rather than trying to fit an inappropriate header file into Windows, is simply to remove the line:
#include <unistd.h>
then try and compile your code.
You may find (if you're extremely lucky) 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.
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.

- 854,327
- 234
- 1,573
- 1,953
If you need a minimal GNU environment for windows with some of the functionality of unistd.h
, you would look to the MinGW project first. If you're lucky, you can get away without using their compiled libraries at all.
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.

- 35,651
- 4
- 70
- 100