Compiler Error with Mingw64 on Windows 10


#1

Hi! I'm having some trouble compiling the latest version of JUCE on MinGW64 on Windows 10. 

In the juce_win32_ComSmartPtr.h file, it defines __uuidof:

#if ! (defined (_MSC_VER) || defined (__uuidof))
  template<typename Type> struct UUIDGetter { static CLSID get() { jassertfalse; return CLSID(); } };
  #define __uuidof(x) UUIDGetter<x>::get()
#endif

However, this code is not run on Mingw64, due to the fact __uuidof is already defined in _mingw.h:

#define __uuidof(type) __mingw_uuidof<__typeof(type)>()

Here is the error that finally bubbles up during compiling:

In file included from ...juce_win32_WASAPI.cpp:101:23: error: 'UUIDGetter' is not a class template
     template<> struct UUIDGetter<name>   { static CLSID get() { return uuidFromString (guid); } };

Just curious if anyone has any suggestions. Should the build-in __uuidof be undefined and re-defined by JUCE? Does the JUCE code need to handle MinGW differently? 

Thanks!
Jonathan


#2

I don't have a mingw64 test system right now. Can you replace the #if JUCE_MINGW on line 98 in 
juce_win32_WASAPI.cpp with #if ! (defined (_MSC_VER) || defined (__uuidof)) ? Does that work?
 

 


#3

TBH now that mingw has implemented __uuidof, we should probably remove that UUIDGetter stuff altogether. Its only purpose was to allow older versions of mingw to compile without errors, but it would never actually work.


#4

Thanks Fabian! I gave that a try, and while it fixed the imediate error, it caused some other issues in juce_win32_WASAPI.cpp.

This is the JUCE_COMCLASS and JUCE_IUNKNOWNCLASS that is now being defined for MinGW64:

#define JUCE_COMCLASS(name, guid) struct __declspec (uuid (guid)) name

#define JUCE_IUNKNOWNCLASS(name, guid) JUCE_COMCLASS(name, guid) : public IUnknown

And that causes lots of compiler errors like this one:

juce_win32_WASAPI.cpp:136:21: warning: 'uuid' attribute directive ignored [-Wattributes]
 JUCE_IUNKNOWNCLASS (IPropertyStore, "886d8eeb-8cf2-4446-8d02-cdba1dbdcf99")
                     ^

juce_win32_WASAPI.cpp:112:74: note: in definition of macro 'JUCE_COMCLASS'
  #define JUCE_COMCLASS(name, guid)       struct __declspec (uuid (guid)) name
                                                                          ^

juce_win32_WASAPI.cpp:136:1: note: in expansion of macro 'JUCE_IUNKNOWNCLASS'
 JUCE_IUNKNOWNCLASS (IPropertyStore, "886d8eeb-8cf2-4446-8d02-cdba1dbdcf99")
 ^

And even some linking errors:

juce_win32_WASAPI.cpp:527: undefined reference to `_GUID const& __mingw_uuidof<juce::IAudioSessionControl>()'
CMakeFiles\openshot-audio.dir/objects.a(juce_audio_devices.cpp.obj): In function `ZN4juce13WasapiClasses16WASAPIDeviceBase12createClientEv':

#5

Hello,

I'm realy newbie to JUCE but i got into the same problem when i was trying to review it and running a tutorial.

When i saw the others comments up here i tried to play with the macro and i succeded to build the tutorial by changing

#if ! (defined (_MSC_VER) || defined (__uuidof))

to

#if ! (defined (_MSC_VER))

in file: juce_win32_ComSmartPtr.h

I'm not sure if its legal but it worked.

Avi.


#6

Thanks for the suggestions everyone! I've found the _mingw.h defined macros to be incompatible with JUCE, as far as I can tell. Using the MinGW64 defines for (__uuidof, KSDATAFORMAT_SUBTYPE_PCM, KSDATAFORMAT_SUBTYPE_IEEE_FLOAT), creates lots of compile and linker errors.

My basic approach is to just undefine them, and use the JUCE included defines... and that seems to work fine. For example:

#if JUCE_MINGW && defined(__uuidof)
  #undef __uuidof
#endif

I've attached a patch which fixes all the compiler and linker errors for MinGW (with regards to WASAPI, which is what I'm testing right now).  Please let me know what you think. Okay, I'm unable to attach a TXT patch file to this post... so I'm including it here (sorry).


Index: JuceLibraryCode/modules/juce_core/native/juce_BasicNativeHeaders.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252

— JuceLibraryCode/modules/juce_core/native/juce_BasicNativeHeaders.h    (date 1441235347000)
+++ JuceLibraryCode/modules/juce_core/native/juce_BasicNativeHeaders.h    (revision )
@@ -104,6 +104,9 @@
  #include <ctime>
  #include <wininet.h>
  #include <nb30.h>

  • #if JUCE_MINGW
  •  #include <winsock2.h>
  • #endif
      #include <iphlpapi.h>
      #include <mapi.h>
      #include <float.h>
    Index: JuceLibraryCode/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>windows-1252
    ===================================================================
    — JuceLibraryCode/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp    (date 1441235347000)
    +++ JuceLibraryCode/modules/juce_audio_devices/native/juce_win32_WASAPI.cpp    (revision )
    @@ -112,6 +112,11 @@
      #define JUCE_COMCLASS(name, guid)       struct __declspec (uuid (guid)) name
     #endif
     
    +#if JUCE_MINGW && defined(KSDATAFORMAT_SUBTYPE_PCM)
  •    #undef KSDATAFORMAT_SUBTYPE_PCM
  •    #undef KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
    +#endif

 #ifndef KSDATAFORMAT_SUBTYPE_PCM
  #define KSDATAFORMAT_SUBTYPE_PCM         uuidFromString (“00000001-0000-0010-8000-00aa00389b71”)
  #define KSDATAFORMAT_SUBTYPE_IEEE_FLOAT  uuidFromString (“00000003-0000-0010-8000-00aa00389b71”)
Index: JuceLibraryCode/modules/juce_core/native/juce_win32_ComSmartPtr.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252

— JuceLibraryCode/modules/juce_core/native/juce_win32_ComSmartPtr.h    (date 1441235347000)
+++ JuceLibraryCode/modules/juce_core/native/juce_win32_ComSmartPtr.h    (revision )
@@ -29,6 +29,10 @@
 #ifndef JUCE_WIN32_COMSMARTPTR_H_INCLUDED
 #define JUCE_WIN32_COMSMARTPTR_H_INCLUDED
 
+#if JUCE_MINGW && defined(__uuidof)

  •  #undef __uuidof
    +#endif

 #if ! (defined (_MSC_VER) || defined (__uuidof))
 template<typename Type> struct UUIDGetter { static CLSID get() { jassertfalse; return CLSID(); } };
 #define __uuidof(x)  UUIDGetter<x>::get()
Index: JuceLibraryCode/modules/juce_core/maths/juce_MathsFunctions.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252

— JuceLibraryCode/modules/juce_core/maths/juce_MathsFunctions.h    (date 1441235347000)
+++ JuceLibraryCode/modules/juce_core/maths/juce_MathsFunctions.h    (revision )
@@ -376,7 +376,7 @@
 template <>
 inline bool juce_isfinite (float value) noexcept
 {

  •   #if JUCE_WINDOWS
  •   #if JUCE_WINDOWS && !JUCE_MINGW
         return _finite (value) != 0;
        #else
         return std::isfinite (value);
    @@ -386,7 +386,7 @@
     template <>
     inline bool juce_isfinite (double value) noexcept
     {
  •   #if JUCE_WINDOWS
  •   #if JUCE_WINDOWS && !JUCE_MINGW
         return _finite (value) != 0;
        #else
         return std::isfinite (value);

It would be great if this patch (or something similar) could be applied to the source code. Next stop, JUCE_ASIO, which also has some MinGW64 compile errors (I'll create a new post for that). Thanks again!

Thanks!
-Jonathan Thomas


#7

correct me if I'm wrong, but isn't that juce define "empty"?
afaik it does nothing and is there just to make the code actually build&link.

 


#8

I now have JUCE_ASIO working in MinGW64... and it turned out to be very simple, so I figured I would just attach it to this same thread. Here is the error I get by default when I enable JUCE_ASIO:

juce_win32_ASIO.cpp:1419:15: error: explicit specialization in non-namespace scope 'class juce::ASIOAudioIODevice'
     template <>
               ^

Here is my patch to fix it. Basically, I'm just moving this one template outside of the class (right below it). Apparently MinGW can't figure it out, although some compilers work just fine with that syntax.


Index: JuceLibraryCode/modules/juce_audio_devices/native/juce_win32_ASIO.cpp
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>windows-1252

— JuceLibraryCode/modules/juce_audio_devices/native/juce_win32_ASIO.cpp    (date 1441314603000)
+++ JuceLibraryCode/modules/juce_audio_devices/native/juce_win32_ASIO.cpp    (revision )
@@ -1416,18 +1416,18 @@
         }
     };
 

  •    template <>
  •    struct ASIOCallbackFunctions <sizeof(currentASIODev) / sizeof(currentASIODev[0])>
  •    {
  •        static void setCallbacksForDevice (ASIOCallbacks&, ASIOAudioIODevice*) noexcept {}
  •    };

     void setCallbackFunctions() noexcept
     {
         ASIOCallbackFunctions<0>::setCallbacksForDevice (callbacks, this);
     }
 
     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ASIOAudioIODevice)
+};
+
+template <>
+struct ASIOAudioIODevice::ASIOCallbackFunctions <sizeof(currentASIODev) / sizeof(currentASIODev[0])>
+{

  •    static void setCallbacksForDevice (ASIOCallbacks&, ASIOAudioIODevice*) noexcept {}
     };
     
     //==============================================================================

Please let me know if you have any suggestions to improve either of these patches. I would be happy to test them on MinGW64.

Thanks!
Jonathan Thomas


#9

Thank you Jonathan. I had the same problem cross-compiling on Linux (mxe / gcc 4.9.3).

 

Maybe this should be put into the repository? I don't know what the issue regarding http://www.juce.com/comment/314824#comment-314824 is, but at least it compiles with the above patch.


#10

I've added a few of these changes. Let me know if there's anything left, as we don't test with mingw.

One thing I didn't add was the __uuidof change - if there's already a macro defined for that symbol, then surely it means that proper support for __uuidof is available? The juce version is just a bit of a hacky fall-back for compilers where there's no better implementation provided by the compiler.


#11

Hi guys,

This issue is still present in JUCE 4.2.3 if compiled on MinGW64, Windows 7 (64bit), GCC 5.3.0. I was able to fix it as suggested by fabian here, with lots of warnings though (I can paste them here if needed).

Then, a new error pops up:

In file included from ../../JuceLibraryCode/modules/juce_core/juce_core.cpp:212:0, from ../../JuceLibraryCode/juce_core.cpp:9: ../../JuceLibraryCode/modules/juce_core/native/juce_win32_SystemStats.cpp: In function 'void juce::callCPUID(int*, int)' : ../../JuceLibraryCode/modules/juce_core/native/juce_win32_SystemStats.cpp:46:30: error: '__cpuid' was not declared in this scope __cpuid (result, infoType); ^ make: *** [build/intermediate/Debug/juce_core_75b14332.o] Error 1
EDIT

Fixed by including <intrin.h> at the top of juce_win32_SystemStats.cpp as suggested here, but now the linker complains about undefined reference to _GUID const& __mingw_uuidof<[many-juce-classes-here>()


#12

OK the errors and warnings should be fixed on develop.


#13

Great, it worked like a charm. Thank you!