Share via


cannot open source file unistd.h error

Question

Tuesday, May 8, 2018 7:56 AM

Hello

I just installed Visual Studio 2017, and now I am getting an error when I open a project in Visual Studio 2015 that previous built without errors. What is the reason for this error? Is this due to settings changed by VS installation?

Error (active) cannot open source file "unistd.h"     openglProject c:\Program Files (x86)\GnuWin32\include\zconf.h

All replies (11)

Wednesday, May 9, 2018 1:46 AM ✅Answered

Well, the current version of zconf.h for zlib is quite simple, there is only one way unistd.h can get included, unless you somehow managed to run the configure script.

#ifndef Z_SOLO
#  if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
#    include <unistd.h>         /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
#    ifdef VMS
#      include <unixio.h>       /* for off_t */
#    endif
#    ifndef z_off_t
#      define z_off_t off_t
#    endif
#  endif
#endif

You quite literally need to tell the header to use it. So if you somehow defined Z_HAVE_UNISTD_H or HAVE_UNISTD_H then remove them.

This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


Wednesday, May 9, 2018 3:25 PM ✅Answered

Change the line

#if 1

to

#if 0

This will force that block to never activate. Also Visual Studio 2017 doesn't know about GnuWin32. If you use the way that Visual Studio want you to use, vcpkg, then it will go into your user profile directory so what ever updated this was not Visual Studio.

This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


Tuesday, May 8, 2018 11:18 AM

When you installed Visual Studio 2017, did you include the VC2015 build tools?

This does slightly change the version of the compiler so it could be causing detection in that zconf.h file to fail now.

But you will have to look at the header yourself and see what pre-processor macros are active and inactive and find what it should be doing and figure out how to do it.

This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


Tuesday, May 8, 2018 11:27 AM | 1 vote

Have you added the directory in VC++ Include directories ?

(those headers are not MS SDK headers)


Tuesday, May 8, 2018 10:56 PM

When you installed Visual Studio 2017, did you include the VC2015 build tools?

This does slightly change the version of the compiler so it could be causing detection in that zconf.h file to fail now.

But you will have to look at the header yourself and see what pre-processor macros are active and inactive and find what it should be doing and figure out how to do it.

That last bit sound like French to me. I hardly know what I am doing when I mess with header files, and when I interfere with one, it tends to affect other dependencies. If that's what it will take, I think I prefer to start over. Thanks


Tuesday, May 8, 2018 10:59 PM

Have you added the directory in VC++ Include directories ?

All the necessary directories were already added to the VC++ Include Directories. As far as I  know they haven't changed, but I can double check.


Wednesday, May 9, 2018 1:42 AM

The unistd.h header is the Unix/Linux equivalent of windows.h, and as such you don't want anything building for Windows to include unistd.h in the same way that you don't want anything written for Linux/Unix including windows.h.

This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


Wednesday, May 9, 2018 1:11 PM

I did not manually define them, but something must have - maybe VS2017 installation - I don't know, but as to how to remove them, this is where I need your help, 'cause I don't have a clue.

This is what's in my zconf.h

#if 1           /* HAVE_UNISTD_H -- this line is updated by ./configure */
#  include <sys/types.h> /* for off_t */
#  include <unistd.h>    /* for SEEK_* and off_t */
#  ifdef VMS
#    include <unixio.h>   /* for off_t */
#  endif
#  define z_off_t off_t
#endif

How, and where do I remove HAVE_UNISTD_H

If I reinstall zlib, do you think that might reset the configuration? Nope. Didn't work.


Wednesday, May 9, 2018 5:40 PM

Been trying to change the contents of the file, but I can't save it, since it's denying me access. What do you recommend as the best method to gain access to the file?


Wednesday, May 9, 2018 5:51 PM

Well, since it is in Program Files (x86) it would require administrative rights, so run Visual Studio as administrator.

This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.


Wednesday, May 9, 2018 6:10 PM

Well, that fixed it. Cool. Thanks