While trying to build Octave for mingw, I hit the following error: ../../liboctave/system/oct-env.cc: In member function 'std::string octave_env::do_get_host_name() const': ../../liboctave/system/oct-env.cc:455:20: error: 'gethostname' is not a member of 'gnulib' ../../liboctave/system/oct-env.cc:455:20: note: suggested alternative: In file included from /scratch/jwe/src/mxe-octave-hg/usr/i686-pc-mingw32/include/windows.h:98:0, from /scratch/jwe/src/mxe-octave-hg/usr/i686-pc-mingw32/include/pthread.h:198, from ../libgnu/time.h:369, from ../libgnu/wchar.h:72, from /scratch/jwe/src/mxe-octave/usr/lib/gcc/i686-pc-mingw32/4.7.2/include/c++/cwchar:46, from /scratch/jwe/src/mxe-octave/usr/lib/gcc/i686-pc-mingw32/4.7.2/include/c++/bits/postypes.h:42, from /scratch/jwe/src/mxe-octave/usr/lib/gcc/i686-pc-mingw32/4.7.2/include/c++/bits/char_traits.h:42, from /scratch/jwe/src/mxe-octave/usr/lib/gcc/i686-pc-mingw32/4.7.2/include/c++/string:42, from ../../liboctave/system/oct-env.cc:47: /scratch/jwe/src/mxe-octave-hg/usr/i686-pc-mingw32/include/winsock2.h:635:12: note: 'gethostname'
Gnulib's unistd.h is included from oct-env.cc. Oddly, including it twice avoids the above problem. In trying to track down the source of the problem, I noticed the following lines in gnulib's unistd.in.h: /* 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 @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \ && !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 @HAVE_UNISTD_H@ # @INCLUDE_NEXT@ @NEXT_UNISTD_H@ # else # error unexpected; report this to bug-gnulib@gnu.org # endif # define _GL_WINSOCK2_H_WITNESS /* Normal invocation. */ #elif !defined _@GUARD_PREFIX@_UNISTD_H It looks like this code may be out of date for current versions of mingw. As far as I can tell the version of winsock2.h that I'm using from the w32api-3.17-2-mingw32-dev distribution available from http://sourceforge.net/projects/mingw does not include unistd.h. Changing the gnulib unistd.h.in file to have #if !defined _@GUARD_PREFIX@_UNISTD_H instead of the lines shown above also solves the problem for me. I'm not sure how best to fix this so that it works for current mingw systems that do not seem to need the special treatment and older versions that apparently do. I'd be glad to provide any other information that would be helpful in solving this problem. jwe