Cannot open include file: 'unistd.h': No such file or directory
Asked Answered
B

4

44

After having installed libpng into my computer, I've included it into my project using #include <png.h> on a Windows 7 SP1 plateform and using Visual Studio Ultimate 2013.

But at build time, I'm getting this error:

C1083: Cannot open include file: 'unistd.h': No such file or directory

How do I please to fix this? I haven't found yet any solution in the net?

Bryna answered 28/3, 2014 at 6:31 Comment(4)
I have at final followed this proposition.Bryna
I've never had trouble building libpng with Visual Studio. Chances are there's an #ifdef around the platform specific parts and you just need to provide the right definitions to select the right platform.Quaternary
@RetiredNinja, thanks for your response, does libpng allows convsion from bitmap to png?Bryna
Well, it isn't called lippngandbmp, so not directly, no. If you had a bmp file in memory it isn't difficult to use libpng to write a png file.Quaternary
D
48

The "uni" in unistd stands for "UNIX" - you won't find it on a Windows system.

Most widely used, portable libraries should offer alternative builds or detect the platform and only try to use headers/functions that will be provided, so it's worth checking documentation to see if you've missed some build step - e.g. perhaps running "make" instead of loading a ".sln" Visual C++ solution file.

If you need to fix it yourself, remove the include and see which functions are actually needed, then try to find a Windows equivalent.

Distasteful answered 28/3, 2014 at 6:38 Comment(3)
Thanks a lot for your response, I have at final followed this proposition.Bryna
Oh - good find - GNU, Cygwin and a few other offerings approximate UNIX environments on Windows. The Microsoft Visual C++ compiler and O.S. itself seems to go out of its way not to... (e.g. lack of posix threads, Winsock / BSD incompatibilities, missing header for int8_t et al).Distasteful
@TonyD The header that includes int8_t and that family of similar types is included starting with Visual Studio 2010, when MS finally added support for <stdint.h>Mash
C
31

If you're using ZLib in your project, then you need to find :

#if 1

in zconf.h and replace(uncomment) it with :

#if HAVE_UNISTD_H /* ...the rest of the line

If it isn't ZLib I guess you should find some alternative way to do this. GL.

Cybil answered 25/6, 2014 at 20:10 Comment(1)
Hi, I understand this is a fairly old question, but I'd be glad if you help me. I am trying to build LibRaw which has dependency both for Zlib and Jasper. When I don't use jasper (it's optional), i.e. don't define USE_JASPER everything builds correctly, but with jasper I am getting the same error as the asker. So IDK where this definition happens is there a global way to disable it?Androgyne
L
1

My solution for this is to replace

#include <unistd.h>

with

#ifdef _WIN32
#include <io.h>
#define access _access

#else
#include <unistd.h>
#endif

That will load io.h for Windows builds and load unistd for *nix builds.

Lumpy answered 24/4 at 19:5 Comment(0)
S
0

Change your C++ standard to C++17 from your project directory. because you do not need to unistd.h in C++17 standard in VS.

Strum answered 18/5, 2022 at 15:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.