Menu

Patch to enable compilation with Visual C++ 2015

wpkg
MH
2015-09-16
2015-09-17
  • MH

    MH - 2015-09-16

    Microsoft Visual Studio 2015 finally implements the C99 function snprintf. MSVC's version of tzname is prefixed with an underscore. While I don't have an earlier version of Visual Studio lying around, what I can gather is that there was a a deprecated variable with that name. What's not taken care of with this patch is the msvc-runtime package with the Visual C++ runtime.

    diff --git a/wpkg/libdebpackages/compatibility.cpp b/wpkg/libdebpackages/compatibility.cpp
    index c077c6c..6ebb1e8 100644
    --- a/wpkg/libdebpackages/compatibility.cpp
    +++ b/wpkg/libdebpackages/compatibility.cpp
    @@ -32,12 +32,14 @@
     #include    <vector>
    
     #ifdef _MSC_VER
    +#if _MSC_VER < 1900
     int snprintf(char *output, size_t size, const char *format, ...)
     {
         va_list ap;
         va_start(ap, format);
         return _vsnprintf(output, size, format, ap);
     }
    +#endif
    
     int strcasecmp(const char *a, const char *b)
     {
    diff --git a/wpkg/libdebpackages/libdebpackages/compatibility.h b/wpkg/libdebpackages/libdebpackages/compatibility.h
    index 966ee01..6ba88bb 100644
    --- a/wpkg/libdebpackages/libdebpackages/compatibility.h
    +++ b/wpkg/libdebpackages/libdebpackages/compatibility.h
    @@ -54,7 +54,9 @@ extern "C" DEBIAN_PACKAGE_EXPORT char * strptime(const char *buf, const char *fm
     #ifdef _MSC_VER
     typedef int mode_t;
    
    +#if _MSC_VER < 1900
     DEBIAN_PACKAGE_EXPORT int snprintf(char *output, size_t size, const char *format, ...);
    +#endif
     DEBIAN_PACKAGE_EXPORT int strcasecmp(const char *a, const char *b);
     DEBIAN_PACKAGE_EXPORT int strncasecmp(const char *a, const char *b, size_t c);
    
    diff --git a/wpkg/libdebpackages/strptime.c b/wpkg/libdebpackages/strptime.c
    index da7caff..1f2f35d 100644
    --- a/wpkg/libdebpackages/strptime.c
    +++ b/wpkg/libdebpackages/strptime.c
    @@ -417,7 +417,7 @@ recurse:
                    bp += 3;
                } else {
                    ep = find_string(bp, &i,
    -                            (const char * const *)tzname,
    +                            (const char * const *)_tzname,
                                  NULL, 2);
                    if (ep != NULL) {
                        tm->tm_isdst = i;
    @@ -425,7 +425,7 @@ recurse:
                        tm->TM_GMTOFF = -(timezone);
     #endif
     #ifdef TM_ZONE
    -                   tm->TM_ZONE = tzname[i];
    +                   tm->TM_ZONE = _tzname[i];
     #endif
                    }
                    bp = ep;
    
     
    • R. Douglas Barbieri

      Hi MH,

      Thank you for your patch! I have implemented and pushed a version of it,
      but with minor differences. Try this out and let me know if you can
      compile or not. Thanks!

      PS: I've tried building it under VC2013 and it works. I'd like to know
      that VC2015 also works.

      PPS: for the msvc-runtime package, we need a version that supports
      VC2015 as well. That is something I intend to do at some point, but
      right now the installer will only install the VC2013 runtime support.

      ~Doug

       
      • MH

        MH - 2015-09-17

        Hi Doug

        I've tested revision 522bc0f using Visual C++ 2015 and it does indeed build and work (caveat: the msvc-runtime package and NSIS installer were disabled). Thank you very much for quickly integrating the patches!

        Regards, MH

         

Log in to post a comment.