Compiling Reuben's libpaper-1.2.0 tarball on MSVC, I get this compilation error:
CC libgnu_la-strndup.lo strndup.c C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(85): error C2375: 'free': redefinition; different linkage .\string.h(644): note: see declaration of 'free' This patch fixes it. 2022-05-15 Bruno Haible <[email protected]> string, wchar: Fix compilation error on MSVC (regression 2021-09-07). * lib/string.in.h (free): For MSVC, add the dllimport specification if the MSVC headers have it. * lib/wchar.in.h (free): Likewise. diff --git a/lib/string.in.h b/lib/string.in.h index 33160b2525..3996da9fcb 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -122,8 +122,12 @@ _GL_EXTERN_C void rpl_free (void *); # undef _GL_ATTRIBUTE_DEALLOC_FREE # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1) # else -# if defined _MSC_VER -_GL_EXTERN_C void __cdecl free (void *); +# if defined _MSC_VER && !defined free +_GL_EXTERN_C +# if defined _DLL + __declspec (dllimport) +# endif + void __cdecl free (void *); # else # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) _GL_EXTERN_C void free (void *) throw (); @@ -133,8 +137,12 @@ _GL_EXTERN_C void free (void *); # endif # endif #else -# if defined _MSC_VER -_GL_EXTERN_C void __cdecl free (void *); +# if defined _MSC_VER && !defined free +_GL_EXTERN_C +# if defined _DLL + __declspec (dllimport) +# endif + void __cdecl free (void *); # else # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) _GL_EXTERN_C void free (void *) throw (); diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 0d5c0b7abe..835ddbe659 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -185,8 +185,12 @@ _GL_EXTERN_C void rpl_free (void *); # undef _GL_ATTRIBUTE_DEALLOC_FREE # define _GL_ATTRIBUTE_DEALLOC_FREE _GL_ATTRIBUTE_DEALLOC (rpl_free, 1) # else -# if defined _MSC_VER -_GL_EXTERN_C void __cdecl free (void *); +# if defined _MSC_VER && !defined free +_GL_EXTERN_C +# if defined _DLL + __declspec (dllimport) +# endif + void __cdecl free (void *); # else # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) _GL_EXTERN_C void free (void *) throw (); @@ -196,8 +200,12 @@ _GL_EXTERN_C void free (void *); # endif # endif #else -# if defined _MSC_VER -_GL_EXTERN_C void __cdecl free (void *); +# if defined _MSC_VER && !defined free +_GL_EXTERN_C +# if defined _DLL + __declspec (dllimport) +# endif + void __cdecl free (void *); # else # if defined __cplusplus && (__GLIBC__ + (__GLIBC_MINOR__ >= 14) > 2) _GL_EXTERN_C void free (void *) throw ();
