Subject: Re: bug#9960: Compiling Emacs trunk with MSVC

From: Eli Zaretskii <[email-masked]>
Date: Sat, 05 Nov 2011 16:16:40 +0200

> Date: Sat, 05 Nov 2011 07:58:12 -0600
> From: Christoph Scholtes <[email-masked]>
> CC: [email-masked], [email-masked]
> 
> On 11/5/2011 7:22 AM, Eli Zaretskii wrote:
> 
> > Does this patch give good results?
> 
> Yes. Better. Thanks.

Committed.

> Then it can't find a definition of `mode_t' in `strmode'.
> 
> This patch will fix this error:
> 
>   /* Define to the equivalent of the C99 'restrict' keyword, or to
>      nothing if this is not supported.  Do not define if restrict is
> @@ -341,6 +345,13 @@
>   # define restrict
>   #endif
> 
> +/* Define to `int' if <sys/types.h> does not define. */
> +#ifdef __GNUC__
> +/* No action required for gcc */
> +#else /* MSVC */
> +#define mode_t int
> +#endif
> +
>   /* A va_copy replacement for MSVC.  */
>   #ifdef _MSC_VER
>   # ifdef _WIN64

Please commit this, thanks.

> After that, I get a link error for ctags:
> 
> ctags.obj : error LNK2019: unresolved external symbol _sys_stat 
> referenced in fu
> nction _process_file_name
> obj/i386/ctags.exe : fatal error LNK1120: 1 unresolved externals
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual 
> Studio 9.0\
> VC\BIN\link.EXE"' : return code '0x460'
> Stop.
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual 
> Studio 9.0\
> VC\BIN\nmake.exe"' : return code '0x2'
> Stop.
> 
> I am not sure what to do about _sys_stat.

Try this one:

=== modified file 'src/s/ms-w32.h'
--- src/s/ms-w32.h	2011-11-05 11:34:56 +0000
+++ src/s/ms-w32.h	2011-11-05 14:15:45 +0000
@@ -191,6 +191,11 @@ struct sigaction {
 #include <sys/timeb.h>
 #include <sys/stat.h>
 #include <signal.h>
+
+/* MSVC gets link-time errors without these redirections.  */
+#define fstat(a, b) sys_fstat(a, b)
+#define stat(a, b)  sys_stat(a, b)
+#define utime       sys_utime
 #endif
 
 /* Calls that are emulated or shadowed.  */
@@ -279,18 +284,10 @@ typedef int pid_t;
 
 #if !defined (_MSC_VER) || (_MSC_VER < 1400)
 #define tzname    _tzname
+#undef  utime
 #define utime	  _utime
 #endif
 
-#ifdef _MSC_VER
-/* MSVC gets link-time errors without these redirections.  */
-#define fstat(a, b) sys_fstat(a, b)
-#define stat(a, b)  sys_stat(a, b)
-#if _MSC_VER >= 1400
-#define utime       sys_utime
-#endif
-#endif
-
 /* This is hacky, but is necessary to avoid warnings about macro
    redefinitions using the SDK compilers.  */
 #ifndef __STDC__