[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problem with including <unistd.h>
From: |
Benjamin Lindner |
Subject: |
Problem with including <unistd.h> |
Date: |
Thu, 27 Jan 2011 13:05:50 +0100 |
Hello list,
building octave for MinGW platform currently encounters compilation
errors in connection with gnulib's unistd.h header file.
Currently octave includes <unistd.h> (among other headers), and then
uses e.g. gnulib::gethostname(), but g++ complains about gethostname
not beloning to namespace gnulib (i.e. having no definition for it).
Strangely, the error disappears, if <unistd.h> is included *twice* in
the corresponding source file.
Debugging the preprocessed source code I found that effectively the
whole unistd.h header was discarded on the first inclusion, and only
the second inclusion really works.
I tracked the problem down to the first #if statements in unistd.h
which on my platform read
/* Special invocation convention:
- On mingw, several headers, including <winsock2.h>, include <unistd.h>,
but we need to ensure that both the system <unistd.h> and <winsock2.h>
are completely included before we replace gethostname. */
#if 1 && 1 \
&& !defined _GL_WINSOCK2_H_WITNESS && defined _WINSOCK2_H
/* <unistd.h> is being indirectly included for the first time from
<winsock2.h>; avoid declaring any overrides. */
# if 1
# include_next <unistd.h>
# else
# error unexpected; report this to address@hidden
# endif
# define _GL_WINSOCK2_H_WITNESS
/* Normal invocation. */
#elif !defined _GL_UNISTD_H
Now, if _WINSOCK2_H is defined before unistd.h is included (as this
was the case for octave, because windows.h was included before
unistd.h) this #if clause is true, so it skips all of the remaining
part of the header (after the #elif statement).
Only on the second inclusion, the first #if statement fails (because
_GL_WINSOCK2_H_WITNESS is now defined), so g++ proceeds beyond the
#elif statement and properly includes the rest of the header.
So currently, it would require unistd.h to be either included twice,
or be included before winsock2.h to work properly.
benjamin
- Problem with including <unistd.h>,
Benjamin Lindner <=