Compile Bullet 2.83 on MinGW [HELP]

Post Reply
drsly
Posts: 4
Joined: Thu Sep 17, 2015 8:27 am

Compile Bullet 2.83 on MinGW [HELP]

Post by drsly »

Has anyone been able to build the latest release on MinGW?

I get errors not too far into the compilation, which I think might be incompatibility between MS/MinGW C runtime libraries:

Code: Select all

[  3%] Building CXX object examples/ThirdPartyLibs/Gwen/CMakeFiles/gwen.dir/Gwen.obj
In file included from C:/OgreDEV/bullet3-2.83.6/examples/ThirdPartyLibs/Gwen/Gwen.h:30:0,
                 from C:\OgreDEV\bullet3-2.83.6\examples\ThirdPartyLibs\Gwen\Gwen.cpp:8:
C:\OgreDEV\bullet3-2.83.6\examples\ThirdPartyLibs\Gwen\Gwen.cpp: In function 'void Gwen::Debug::Msg(const char*, ...)':
C:\OgreDEV\bullet3-2.83.6\examples\ThirdPartyLibs\Gwen\Gwen.cpp:26:52: error: '_TRUNCATE' was not declared in this scope
    GwenUtil_VSNPrintFSafe( strOut, sizeof(strOut), _TRUNCATE, str, s );
                                                    ^
C:/OgreDEV/bullet3-2.83.6/examples/ThirdPartyLibs/Gwen/Macros.h:25:116: note: in definition of macro 'GwenUtil_VSNPrintFSafe'
  #define GwenUtil_VSNPrintFSafe( _DstBuf, _DstSize, _MaxCount, _Format, _ArgLis
t ) vsnprintf_s( _DstBuf, _DstSize, _MaxCount, _Format, _ArgList )

                                    ^
In file included from C:/OgreDEV/bullet3-2.83.6/examples/ThirdPartyLibs/Gwen/Gwen.h:30:0,
                 from C:\OgreDEV\bullet3-2.83.6\examples\ThirdPartyLibs\Gwen\Gwen.cpp:8:
C:/OgreDEV/bullet3-2.83.6/examples/ThirdPartyLibs/Gwen/Macros.h:25:145: error: 'vsnprintf_s' was not declared in this scope
  #define GwenUtil_VSNPrintFSafe( _DstBuf, _DstSize, _MaxCount, _Format, _ArgLis
t ) vsnprintf_s( _DstBuf, _DstSize, _MaxCount, _Format, _ArgList )

                                                                 ^
C:\OgreDEV\bullet3-2.83.6\examples\ThirdPartyLibs\Gwen\Gwen.cpp:26:4: note: in expansion of macro 'GwenUtil_VSNPrintFSafe'
    GwenUtil_VSNPrintFSafe( strOut, sizeof(strOut), _TRUNCATE, str, s );
    ^
examples\ThirdPartyLibs\Gwen\CMakeFiles\gwen.dir\build.make:162: recipe for target 'examples/ThirdPartyLibs/Gwen/CMakeFiles/gwen.dir/Gwen.obj' failed
mingw32-make[2]: *** [examples/ThirdPartyLibs/Gwen/CMakeFiles/gwen.dir/Gwen.obj] Error 1
CMakeFiles\Makefile2:379: recipe for target 'examples/ThirdPartyLibs/Gwen/CMakeFiles/gwen.dir/all' failed
mingw32-make[1]: *** [examples/ThirdPartyLibs/Gwen/CMakeFiles/gwen.dir/all] Error 2
Makefile:126: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
Any tips on how to build?

TIA
Last edited by drsly on Thu Sep 24, 2015 1:07 pm, edited 1 time in total.
drsly
Posts: 4
Joined: Thu Sep 17, 2015 8:27 am

Re: Compile Bullet 2.83 on MinGW

Post by drsly »

Just tried building with mingw-w64

This time the build went further, but there are still errors:

Code: Select all

C:\OgreDEV\bullet3-2.83.6\Extras\Serialize\BulletFileLoader\bFile.cpp:464:13: error: cast from 'char*' to 'long int' loses precision [-fpermissive]
   nr= (long)cp;
FWIW I'm not the only one to experience this:
https://github.com/bulletphysics/bullet3/issues/394

Is anyone able to help??
drsly
Posts: 4
Joined: Thu Sep 17, 2015 8:27 am

Re: Compile Bullet 2.83 on MinGW [HELP]

Post by drsly »

Solved (maybe)?

Compiled ok after changing a dozen or so instances of long to intptr_t

In these files:
src\Bullet3Serialize\Bullet2FileLoader\b3File.cpp
src\Bullet3Serialize\Bullet2FileLoader\b3DNA.cpp
Extras\Serialize\BulletFileLoader\bFile.cpp
Extras\Serialize\BulletFileLoader\bDNA.cpp

The code involved appears to be doing some sort of pointer arithmetic, hopefully changing the data type hasn't broken anything :mrgreen:
d3x0r
Posts: 51
Joined: Tue Dec 11, 2012 9:59 pm

Re: Compile Bullet 2.83 on MinGW [HELP]

Post by d3x0r »

/* _TRUNCATE */
#if !defined(_TRUNCATE)
#define _TRUNCATE ((size_t)-1)
#endif

But that won't fix all the issues...

Code: Select all

--- a/examples/ThirdPartyLibs/Gwen/Macros.h
+++ b/examples/ThirdPartyLibs/Gwen/Macros.h
@@ -4,6 +4,7 @@
 #define GWEN_MACROS_H
 #include <stdlib.h>
 #include <stdarg.h>
+#include <stdio.h> // vsnprintf
 #ifndef __APPLE__
 #include <malloc.h>
 #endif //__APPLE__
@@ -15,13 +16,18 @@
 #define GwenUtil_Max( a, b ) ( ( (a) > (b) ) ? (a) : (b) )
 #define GwenUtil_VSWPrintFSafeSized( _DstBuf_ARRAY_, _Format, _ArgList ) GwenUtil_VSWPrintFSafe( _DstBuf_ARRAY_, sizeof( _DstBuf_ARRAY_ ) / sizeof( wchar_t ), _Format, _ArgList )
 
-#ifdef _WIN32
+#ifdef _MSC_VER
 
 	#ifndef NOMINMAX
         #define NOMINMAX
         #endif
 	#include <windows.h>
 
+	/* _TRUNCATE */
+	#if !defined(_TRUNCATE)
+		#define _TRUNCATE ((size_t)-1)
+	#endif
+
 	#define GwenUtil_VSNPrintFSafe( _DstBuf, _DstSize, _MaxCount, _Format, _ArgList ) vsnprintf_s( _DstBuf, _DstSize, _MaxCount, _Format, _ArgList )
 	#define GwenUtil_VSWPrintFSafe( _DstBuf, _SizeInWords, _Format, _ArgList ) vswprintf_s( _DstBuf, _SizeInWords, _Format, _ArgList )
 	#define GwenUtil_OutputDebugCharString( lpOutputString ) OutputDebugStringA( lpOutputString )
@@ -38,10 +44,14 @@
 	#define GwenUtil_OutputDebugWideString( lpOutputString ) //wprintf( lpOutputString  )
 	#define GwenUtil_WideStringToFloat( _Str ) wcstof(_Str, NULL)
 
-#elif defined(__linux__)
+#elif defined(__linux__) || defined( __GNUC__ )
 
-	#define GwenUtil_VSNPrintFSafe( _DstBuf, _DstSize, _MaxCount, _Format, _ArgList ) vsnprintf( _DstBuf, _DstSize, _Format, _ArgList )
-	#define GwenUtil_VSWPrintFSafe( _DstBuf, _SizeInWords, _Format, _ArgList ) vswprintf( _DstBuf, _SizeInWords, _Format, _ArgList )
+	#define GwenUtil_VSNPrintFSafe( _DstBuf, _DstSize, _MaxCount, _Format, _ArgList ) vsnprintf( _DstBuf, _DstSize, _Format, _ArgList )
+	#ifdef _WIN32
+		#define GwenUtil_VSWPrintFSafe( _DstBuf, _SizeInWords, _Format, _ArgList ) vsnwprintf( _DstBuf, _SizeInWords, _Format, _ArgList )
+	#else
+		#define GwenUtil_VSWPrintFSafe( _DstBuf, _SizeInWords, _Format, _ArgList ) vswprintf( _DstBuf, _SizeInWords, _Format, _ArgList )
+	#endif
 	#define GwenUtil_OutputDebugCharString( lpOutputString ) //printf( lpOutputString )
 	#define GwenUtil_OutputDebugWideString( lpOutputString ) //wprintf( lpOutputString  )
 	#define GwenUtil_WideStringToFloat( _Str ) wcstof(_Str, NULL)

unfortunatly the 'C Standard' defined vswprintf() to already have a length; but msvcrt which MinGW links against is vsnwprintf and vsnprintf.
I suppose that ucrt(http://blogs.msdn.com/b/vcblog/archive/ ... l-crt.aspx) will fix that in the future too so that will be another complication.

Another line would have to be changed here....

Code: Select all

diff --git a/examples/OpenGLWindow/Win32Window.cpp b/examples/OpenGLWindow/Win32Window.cpp
index 245ccb7..9f8a245 100644
--- a/examples/OpenGLWindow/Win32Window.cpp
+++ b/examples/OpenGLWindow/Win32Window.cpp
@@ -432,8 +432,11 @@ void Win32Window::setWindowTitle(const char* titleChar)
 {

        wchar_t  windowTitle[1024];
+#ifdef _WIN32
+       snwprintf(windowTitle, 1024, L"%hs", titleChar);
+#else
        swprintf(windowTitle, 1024, L"%hs", titleChar);
-
+#endif
        DWORD dwResult;

 #ifdef _WIN64
I'd actually think this would be a better fix; get rid of the convert char to wchar.. since you're not going to get anything anyway.

Code: Select all

diff --git a/examples/OpenGLWindow/Win32Window.cpp b/examples/OpenGLWindow/Win32Window.cpp
index 245ccb7..39192ff 100644
--- a/examples/OpenGLWindow/Win32Window.cpp
+++ b/examples/OpenGLWindow/Win32Window.cpp
@@ -431,16 +431,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 void Win32Window::setWindowTitle(const char* titleChar)
 {

-       wchar_t  windowTitle[1024];
-       swprintf(windowTitle, 1024, L"%hs", titleChar);
-
        DWORD dwResult;

 #ifdef _WIN64
-               SetWindowTextW(m_data->m_hWnd, windowTitle);
+               SetWindowText(m_data->m_hWnd, titleChar);
 #else
-               SendMessageTimeoutW(m_data->m_hWnd, WM_SETTEXT, 0,
-                               reinterpret_cast<LPARAM>(windowTitle),
+               SendMessageTimeout(m_data->m_hWnd, WM_SETTEXT, 0,
+                               reinterpret_cast<LPARAM>(titleChar),
                                SMTO_ABORTIFHUNG, 2000, &dwResult);
 #endif
 }
Though might be better in that case to replace W functions with Char functions... but then again maybe utf8 support for windows is truly bad.

-------
- OR - disable "BUILD_BULLET2_DEMOS" and bypass that whole issue.
drsly
Posts: 4
Joined: Thu Sep 17, 2015 8:27 am

Re: Compile Bullet 2.83 on MinGW [HELP]

Post by drsly »

Thanks, d3x0r

I'm dealing with other issues atm, will come back to this later.

BTW what version of MinGW are did you use?
d3x0r
Posts: 51
Joined: Tue Dec 11, 2012 9:59 pm

Re: Compile Bullet 2.83 on MinGW [HELP]

Post by d3x0r »

A pretty old one?

gcc.exe (GCC) 4.8.1

the _TRUNCATE issue is becuase mingw refuses to maintain their s***.
So that would be fixed with mingw64...
the reset is because windows.
Post Reply