When compiling libiconv for MSVC 9, I'm seeing this error: /home/bruno/msvc/compile cl -nologo -DHAVE_CONFIG_H -DEXEEXT=\".exe\" -I. -I.. -I../lib -I../intl -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1 -D_WIN32_WINNT=_WIN32_WINNT_WINXP -I/usr/local/msvc/include -MD -c canonicalize-lgpl.c canonicalize-lgpl.c C:\Programme\Microsoft Visual Studio 9.0\VC\include\io.h(317) : error C2375: 'rpl_read': redefinition; different binding .\unistd.h(1519): see declaration of 'rpl_read'
Obviously, if <io.h> contains a definition of the read() function, it needs to be #included before we do a "#define read rpl_read". This fixes it and a couple of similar situations. 2012-01-15 Bruno Haible <br...@clisp.org> Improve support for MSVC 9. * lib/unistd.in.h: Include <io.h> when needed to avoid redefinition clashes on MSVC. * lib/fcntl.in.h: Likewise. * lib/stdlib.in.h: Likewise. * lib/sys_stat.in.h: Likewise. --- lib/fcntl.in.h.orig Sun Jan 15 17:32:52 2012 +++ lib/fcntl.in.h Sun Jan 15 17:26:28 2012 @@ -62,6 +62,12 @@ # include <unistd.h> #endif +/* Native Windows platforms declare open(), creat() in <io.h>. */ +#if (@GNULIB_OPEN@ || defined GNULIB_POSIXCHECK) \ + && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include <io.h> +#endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ --- lib/stdlib.in.h.orig Sun Jan 15 17:32:53 2012 +++ lib/stdlib.in.h Sun Jan 15 17:27:20 2012 @@ -49,6 +49,11 @@ # include <sys/loadavg.h> #endif +/* Native Windows platforms declare mktemp() in <io.h>. */ +#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include <io.h> +#endif + #if @GNULIB_RANDOM_R@ /* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included --- lib/sys_stat.in.h.orig Sun Jan 15 17:32:53 2012 +++ lib/sys_stat.in.h Sun Jan 15 17:23:12 2012 @@ -62,6 +62,11 @@ # include <direct.h> /* mingw64, MSVC 9 */ #endif +/* Native Windows platforms declare umask() in <io.h>. */ +#if 0 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include <io.h> +#endif + #ifndef S_IFIFO # ifdef _S_IFIFO # define S_IFIFO _S_IFIFO --- lib/unistd.in.h.orig Sun Jan 15 17:32:53 2012 +++ lib/unistd.in.h Sun Jan 15 17:31:19 2012 @@ -84,12 +84,19 @@ #endif /* Native Windows platforms declare chdir, getcwd, rmdir in - <io.h> and/or <direct.h>, not in <unistd.h>. */ + <io.h> and/or <direct.h>, not in <unistd.h>. + They also declare access(), chmod(), close(), dup(), dup2(), isatty(), + lseek(), read(), unlink(), write() in <io.h>. */ #if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \ || defined GNULIB_POSIXCHECK) \ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) # include <io.h> /* mingw32, mingw64 */ # include <direct.h> /* mingw64, MSVC 9 */ +#elif (@GNULIB_CLOSE@ || @GNULIB_DUP@ || @GNULIB_DUP2@ || @GNULIB_ISATTY@ \ + || @GNULIB_LSEEK@ || @GNULIB_READ@ || @GNULIB_UNLINK@ || @GNULIB_WRITE@ \ + || defined GNULIB_POSIXCHECK) \ + && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include <io.h> #endif /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.