41

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?

user3471387
  • 427
  • 3
  • 8
  • 10
  • 2
    I have at final followed [this proposition](http://stackoverflow.com/a/2872995/3471387). – user3471387 Mar 28 '14 at 06:40
  • 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. – Retired Ninja Mar 28 '14 at 06:58
  • @RetiredNinja, thanks for your response, does libpng allows convsion from bitmap to png? – user3471387 Mar 28 '14 at 07:10
  • 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. – Retired Ninja Mar 28 '14 at 07:21

3 Answers3

45

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.

Tony Delroy
  • 102,968
  • 15
  • 177
  • 252
  • Thanks a lot for your response, I have at final followed [this proposition](http://stackoverflow.com/a/2872995/3471387). – user3471387 Mar 28 '14 at 06:41
  • 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). – Tony Delroy Mar 28 '14 at 06:43
  • 3
    @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 `` – WhozCraig Mar 28 '14 at 08:37
30

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.

Grokking
  • 665
  • 8
  • 16
  • 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? – Vahagn Tumanyan Mar 31 '16 at 13:54
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.

piyapiya
  • 177
  • 1
  • 1
  • 8