MingW fixes (gcc 4.6)

Hey Jules,

I’m trying to compile Juce, latest tip, under MingW (mingw32 and mingw64), and there are minor issues.

here’s a patch for juce-core module:

[code]diff --git a/modules/juce_core/memory/juce_Memory.h b/modules/juce_core/memory/juce_Memory.h
index 314cfa8…3923657 100644
— a/modules/juce_core/memory/juce_Memory.h
+++ b/modules/juce_core/memory/juce_Memory.h
@@ -27,12 +27,6 @@
#define JUCE_MEMORY_JUCEHEADER

//==============================================================================
-#if JUCE_MINGW

  • /** This allocator is not defined in mingw gcc. */
  • #define alloca __builtin_alloca
    -#endif

-//==============================================================================
/** Fills a block of memory with zeros. /
inline void zeromem (void
memory, size_t numBytes) noexcept { memset (memory, 0, numBytes); }

diff --git a/modules/juce_core/native/juce_BasicNativeHeaders.h b/modules/juce_core/native/juce_BasicNativeHeaders.h
index 43451bb…074506f 100644
— a/modules/juce_core/native/juce_BasicNativeHeaders.h
+++ b/modules/juce_core/native/juce_BasicNativeHeaders.h
@@ -83,7 +83,11 @@

#define STRICT 1
#define WIN32_LEAN_AND_MEAN 1

  • #define _WIN32_WINNT 0x0600
  • #if JUCE_MINGW

  • #define _WIN32_WINNT 0x0501

  • #else

  • #define _WIN32_WINNT 0x0600

  • #endif
    #define _UNICODE 1
    #define UNICODE 1
    #ifndef _WIN32_IE
    diff --git a/modules/juce_core/system/juce_TargetPlatform.h b/modules/juce_core/system/juce_TargetPlatform.h
    index 919621a…d5211c2 100644
    — a/modules/juce_core/system/juce_TargetPlatform.h
    +++ b/modules/juce_core/system/juce_TargetPlatform.h
    @@ -81,6 +81,11 @@

    #ifdef MINGW32
    #define JUCE_MINGW 1

  • #ifdef MINGW64

  •  #define JUCE_64BIT 1
    
  • #else

  •  #define JUCE_32BIT 1
    
  • #endif
    #endif

/** If defined, this indicates that the processor is little-endian. */
[/code]

fixes:

  • ‘alloca’ is now available
  • JUCE_32/64BIT was not being defined for mingw

I’ve set ‘_WIN32_WINNT’ as ‘0x0501’ (mingw fails to build otherwise)

EDIT: forgot this change:

[code]diff --git a/modules/juce_core/maths/juce_MathsFunctions.h b/modules/juce_core/maths/juce_MathsFunctions.h
index b436f52…7608446 100644
— a/modules/juce_core/maths/juce_MathsFunctions.h
+++ b/modules/juce_core/maths/juce_MathsFunctions.h
@@ -285,7 +285,7 @@ inline int numElementsInArray (Type (&array)[N])
template
inline Type juce_hypot (Type a, Type b) noexcept
{

  • #if JUCE_WINDOWS
  • #if JUCE_WINDOWS && ! JUCE_MINGW
    return static_cast (_hypot (a, b));
    #else
    return static_cast (hypot (a, b));
    [/code]

I’ll try to build the other modules and we’ll write here patches as needed

gui-basics requires a small change but still fails to build on mingw64 due to FARPROC* to void* cast, so I’ve added a workaround for now.

[code]diff --git a/modules/juce_gui_basics/juce_gui_basics.cpp b/modules/juce_gui_basics/juce_gui_basics.cpp
index 2e03353…31ef851 100644
— a/modules/juce_gui_basics/juce_gui_basics.cpp
+++ b/modules/juce_gui_basics/juce_gui_basics.cpp
@@ -85,7 +85,7 @@
#endif

#if JUCE_MINGW

  • #include <Imm.h>
  • #include <imm.h>
    #endif

//==============================================================================
diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp
index 3cd2e77…2fd8e83 100644
— a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp
+++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp
@@ -54,7 +54,11 @@ void* getUser32Function (const char* functionName) // (NB: this function also us
HMODULE user32Mod = GetModuleHandleA (“user32.dll”);
jassert (user32Mod != 0);

+#if JUCE_MINGW

  • return (void*)GetProcAddress (user32Mod, functionName);
    +#else
    return static_cast <void*> (GetProcAddress (user32Mod, functionName));
    +#endif
    }

//==============================================================================
[/code]

btw, I’m cross-compiling for windows under linux

Cool, thanks! Those all look pretty sensible, I’ll add them asap.

actually, the version my mingw is using is 0x0502 (I think that means Windows XP SP2).

here are a few more patches I created to make standalones run:

1 - no _create_locale for mingw (2nd part is optional, but I need it locally)

[code]diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp
index 1b2444d…eabeeb8 100644
— a/modules/juce_core/text/juce_String.cpp
+++ b/modules/juce_core/text/juce_String.cpp
@@ -455,7 +455,7 @@ namespace NumberToStringConverters
else
{
// Use a locale-free sprintf where possible (not available on linux AFAICT)

  •       #if JUCE_WINDOWS
    
  •       #if JUCE_WINDOWS && ! JUCE_MINGW
           len = (size_t) _sprintf_l (buffer, "%.9g", _create_locale (LC_NUMERIC, "C"), n);
          #elif JUCE_MAC || JUCE_IOS
           len = (size_t)  sprintf_l (buffer, nullptr, "%.9g", n);
    

diff --git a/modules/juce_gui_basics/application/juce_Initialisation.h b/modules/juce_gui_basics/application/juce_Initialisation.h
index 60f693b…5a7eef2 100644
— a/modules/juce_gui_basics/application/juce_Initialisation.h
+++ b/modules/juce_gui_basics/application/juce_Initialisation.h
@@ -91,7 +91,7 @@ public:

#else
#if JUCE_WINDOWS

  • #if defined (WINAPI) || defined (WINDOWS)
  • #if defined (WINAPI) || defined (WINDOWS) || defined(JUCE_MINGW)
    #define JUCE_MAIN_FUNCTION int __stdcall WinMain (HINSTANCE, HINSTANCE, const LPTSTR, int)
    #elif defined (_UNICODE)
    #define JUCE_MAIN_FUNCTION int __stdcall WinMain (void*, void*, const wchar_t*, int)
    [/code]

2 - vst host code fix (missing some defines in mingw, __cdecl already defined)

[code]diff --git a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp
index 782a366…5391133 100644
— a/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp
+++ b/modules/juce_audio_processors/format_types/juce_VSTPluginFormat.cpp
@@ -46,6 +46,11 @@
#if JUCE_MSVC
#pragma warning (push)
#pragma warning (disable: 4996)
+#elif JUCE_MINGW

  • extern “C” {
  • void _fpreset();
  • void _clearfp();
  • }
    #else
    #define __cdecl
    #endif
    [/code]

I now have working 32bit and 64bit windows standalones, cross-compiled from linux :smiley:

Ok, thanks, I’ve updated those now.

thanks,

since I’ve got your attention (and to not start a new thread just for a small fix), the linux-jack code need a fix for c++11

[code]diff --git a/modules/juce_audio_devices/native/juce_linux_JackAudio.cpp b/modules/juce_audio_devices/native/juce_linux_JackAudio.cpp
index c48be0b…d3880ef 100644
— a/modules/juce_audio_devices/native/juce_linux_JackAudio.cpp
+++ b/modules/juce_audio_devices/native/juce_linux_JackAudio.cpp
@@ -40,7 +40,7 @@ static void* juce_loadJackFunction (const char* const name)
static fn_name##_ptr_t fn = nullptr;
if (fn == nullptr) { fn = (fn_name##_ptr_t)juce_loadJackFunction(#fn_name); }
if (fn) return (*fn)arguments; \

  • else return nullptr; \
  • else return 0;
    }

#define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments)
[/code]
function should return an integer, but nullptr is not one

Ah right, thanks!