We could consider define DECLSPEC_SELECTANY to __attribute__((weak)) for old 
GCC.

Patch for this attached.

W dniu 2017-05-03 o 17:19, David Grayson pisze:
> By the way, it's really not clear to me what specific solution you are
> proposing when you say "ensure each GUID is defined only once" but I'm
> imagining it will introduce new incompatibilities/quirks that people have
> to worry about when switching between Visual Studio and mingw-w64, because
> you would have to prevent any GUID definitions from being emitted by header
> files.
> 
> --David
> 
> On Wed, May 3, 2017 at 8:12 AM, David Grayson <[email protected]>
> wrote:
> 
>>> It sounds like guiddef.h should probably check the GCC major version.
>>>> Based on the tests people have reported in this thread, I would guess
>>> that
>>>> for GCC 6 and above the selectany attribute on the declaration is
>>> required,
>>>> while on GCC 5 and below the selectany attribute on the declaration is
>>>> forbidden. Or we could get fancy and add a test to the configure script
>>> to
>>>> figure out which is the case.
>>> Both require citation from GCC documentation. But neither is an optimal
>>> solution IMHO. I suggest we ensure each GUID is defined only once then
>>> remove that attribute completely.
>>>
>>
>> When you say "optimal", what are you optimizing for?
>>
>> I'm trying to optimize for being able to port code from Visual Studio to
>> mingw-w64.  Microsoft has example code (UsbView) that has a header file
>> that includes the windows.h, followed by initguid.h, followed by
>> winioctl.h.  You can see the header file here:
>>
>> https://github.com/Microsoft/Windows-driver-samples/blob/
>> master/usb/usbview/uvcview.h
>>
>> The UsbView code uses that header file in several different translation
>> units, so you end up having a bunch of duplicate GUID definitions for all
>> the GUIDs defined in winioctl.h, like GUID_DEVINTERFACE_DISK.  To prevent
>> multiple definition errors, the Microsoft header files using the selectany
>> attribute.
>>
>> I don't know why Microsoft engineered such a complicated solution for
>> defining GUIDs, but they did, and I would think we should try to make our
>> header files compatible with it.  If it just takes a few preprocessor if
>> statements that check the GCC version, that seems OK.
>>
>> --David
>>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Mingw-w64-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
> 

diff --git a/mingw-w64-headers/include/guiddef.h 
b/mingw-w64-headers/include/guiddef.h
index 9ecea3e..aaa3316 100644
--- a/mingw-w64-headers/include/guiddef.h
+++ b/mingw-w64-headers/include/guiddef.h
@@ -36,8 +36,12 @@ __extension__ template<typename T> const GUID 
&__mingw_uuidof();
 #endif
 
 #ifndef DECLSPEC_SELECTANY
+#if defined (__GNUC__) && __GNUC__ < 6
+#define DECLSPEC_SELECTANY __attribute__((weak))
+#else
 #define DECLSPEC_SELECTANY __declspec(selectany)
 #endif
+#endif
 
 #ifndef EXTERN_C
 #ifdef __cplusplus
@@ -58,8 +62,7 @@ __extension__ template<typename T> const GUID 
&__mingw_uuidof();
 #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID 
DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
 #endif
 #else
-/* __declspec(selectany) must be applied to initialized objects on GCC 5 hence 
must not be used here. */
-#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID 
name
+#define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID 
DECLSPEC_SELECTANY name
 #endif
 
 #define DEFINE_OLEGUID(name, l, w1, w2) DEFINE_GUID (name, l, w1, w2, 0xc0, 0, 
0, 0, 0, 0, 0, 0x46)
diff --git a/mingw-w64-headers/include/ksguid.h 
b/mingw-w64-headers/include/ksguid.h
index eca0269..71462c2 100644
--- a/mingw-w64-headers/include/ksguid.h
+++ b/mingw-w64-headers/include/ksguid.h
@@ -7,8 +7,12 @@
 #include <guiddef.h>
 
 #ifndef DECLSPEC_SELECTANY
+#if defined (__GNUC__) && __GNUC__ < 6
+#define DECLSPEC_SELECTANY __attribute__((weak))
+#else
 #define DECLSPEC_SELECTANY __declspec(selectany)
 #endif
+#endif
 
 #ifdef DEFINE_GUIDEX
 #undef DEFINE_GUIDEX
diff --git a/mingw-w64-headers/include/ntdef.h 
b/mingw-w64-headers/include/ntdef.h
index e3e29e7..02c9722 100644
--- a/mingw-w64-headers/include/ntdef.h
+++ b/mingw-w64-headers/include/ntdef.h
@@ -273,7 +273,11 @@
 
 #ifndef DECLSPEC_SELECTANY
 #if (_MSC_VER >= 1100) || defined(__GNUC__)
+#if defined (__GNUC__) && __GNUC__ < 6
+#define DECLSPEC_SELECTANY __attribute__((weak))
+#else
 #define DECLSPEC_SELECTANY __declspec(selectany)
+#endif
 #else
 #define DECLSPEC_SELECTANY
 #endif
diff --git a/mingw-w64-headers/include/objsel.h 
b/mingw-w64-headers/include/objsel.h
index 7e8ed1d..5f3a05b 100644
--- a/mingw-w64-headers/include/objsel.h
+++ b/mingw-w64-headers/include/objsel.h
@@ -7,8 +7,12 @@
 #define __OBJSEL_H_
 
 #ifndef DECLSPEC_SELECTANY
+#if defined (__GNUC__) && __GNUC__ < 6
+#define DECLSPEC_SELECTANY __attribute__((weak))
+#else
 #define DECLSPEC_SELECTANY __declspec(selectany)
 #endif
+#endif
 
 #ifndef EXTERN_C
 #ifdef __cplusplus
diff --git a/mingw-w64-headers/include/rpcndr.h 
b/mingw-w64-headers/include/rpcndr.h
index 52de4ad..bd6d6ee 100644
--- a/mingw-w64-headers/include/rpcndr.h
+++ b/mingw-w64-headers/include/rpcndr.h
@@ -750,8 +750,12 @@ typedef unsigned __LONG32 error_status_t;
 #endif
 
 #ifndef DECLSPEC_SELECTANY
+#if defined (__GNUC__) && __GNUC__ < 6
+#define DECLSPEC_SELECTANY __attribute__((weak))
+#else
 #define DECLSPEC_SELECTANY __declspec(selectany)
 #endif
+#endif
 
 #define MIDL_INTERFACE(x) struct
 #ifdef __cplusplus
diff --git a/mingw-w64-headers/include/winnt.h 
b/mingw-w64-headers/include/winnt.h
index 6a5ae9f..8bc9637 100644
--- a/mingw-w64-headers/include/winnt.h
+++ b/mingw-w64-headers/include/winnt.h
@@ -201,8 +201,12 @@ extern "C" {
 #endif
 
 #ifndef DECLSPEC_SELECTANY
+#if defined (__GNUC__) && __GNUC__ < 6
+#define DECLSPEC_SELECTANY __attribute__((weak))
+#else
 #define DECLSPEC_SELECTANY __declspec(selectany)
 #endif
+#endif
 
 #ifndef NOP_FUNCTION
 #if (_MSC_VER >= 1210)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to