Skip to main content

History: TDM MinGW64 build guide

Source of version: 3

Copy to clipboard
            {TOC(showdesc="0",shownum="0",type="fancy")}{TOC}

!I. Introduction
This article will explain the modifications that need to be made to Ogre and Ogre's dependencies, so they can be compiled with TDM 4.9.2 MinGW. Generally, this guide should apply to all MinGW64 editions.
It is meant for building Ogre 1.10.0 from source.




!II. Ogredeps
1. To have a true static build, we also want static OIS. To achieve this we need to build it from source.
First get OIS source package here: [http://sourceforge.net/projects/wgois/|OIS SourceForge repository]
From here on let's assume you extracted the package into '__ois-v-1-3__' (original folder name)

Open '__ois-v-1-3/Win32/ois.cbp__' and go to project build options:
In all the build targets (select OIS), go to compiler search directories and change:
{CODE(wrap="1", colors="none")}C:\Program Files\Microsoft DirectX SDK (November 2008)\Include{CODE}
to {CODE(wrap="1", colors="none")}C:\C++\TDM-4.9.2\x86_64-w64-mingw32\include{CODE} __(This is an example installation dir of TDM, change it to yours)__

In '__OIS_DebugDll__' and '__OIS_ReleaseDll__' build targets add these libraries to linker options: __wbemuuid__, __ole32__, __oleaut32__ (__dinput8__ and __dxguid__ should already be there)

This package is designed to be compiled with MSVC, so we need to make some changes to the source to make it compile under TDM.

Open '__Win32Joystick.cpp__'
At line 587 change this: {CODE(wrap="1", colors="none")}hr = CoCreateInstance(uuidof(WbemLocator), NULL, CLSCTX_INPROC_SERVER, uuidof(IWbemLocator), (LPVOID*)&pIWbemLocator); {CODE}
To this: {CODE(wrap="1", colors="none")}hr = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pIWbemLocator);{CODE}
At lines 637 and 641, replace {CODE(wrap="1", colors="none")}swscanf_s{CODE} with just {CODE(wrap="1", colors="none")}swscanf{CODE}

Now OIS should successfully build with only 25 warnings or so (it's safe to ignore them).
Open '__ois-v-1-3/lib__' and rename __libOIS_static.a__ to __libOIS.a__ (same for the _d version)


2. Now that OIS is succesfully built you need to get the rest of Ogredeps from here: [https://bitbucket.org/cabalistic/ogredeps/downloads|Ogredeps Bitbucket repository]
From here on, let's assume that you extracted the package into 'ogredeps' and used 'ogredeps-build' as the build directory.

On 64 bit systems, you need to change Line 210 of '__ogredeps\src\FreeImage\Source\FreeImage\PluginTIFF.cpp__'
{CODE(wrap="1", colors="none")}// Warning: tif_fd is declared as 'int' currently (see libTIFF), 
    // may result in incorrect file pointers inside libTIFF on 
    // 64bit machines (sizeof(int) != sizeof(long)). 
    // Needs to be fixed within libTIFF.
   if (tif) {
      tif->tif_fd = (long)handle;
   }
 
   return tif;{CODE}
Change to this:
{CODE(wrap="1", colors="none")}tif->tif_fd = (intptr_t)handle;{CODE}

zziplib builds fine itself, but it errors pop up when you try to link against it at the end of building Ogre.
To fix this, you need to open "__ogredeps/src/zziplib/zzip/conf.h__" and change line 25 from: {CODE(wrap="1", colors="none")}# if defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__{CODE} to {CODE(wrap="1", colors="none")}# if defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__ || defined _WIN32{CODE}
and line 162 from {CODE(wrap="1", colors="none")}#if defined _MSC_VER || defined __WATCOMC__{CODE} to {CODE(wrap="1", colors="none")}#if defined _MSC_VER || defined __WATCOMC__ || defined _WIN32{CODE}
and line 166 from {CODE(wrap="1", colors="none")}#ifdef _MSC_VER{CODE} to {CODE(wrap="1", colors="none")}#if defined _MSC_VER || defined _WIN32{CODE}
and line 186 from {CODE(wrap="1", colors="none")}#if defined _MSC_VER || defined __WATCOMC__{CODE} to {CODE(wrap="1", colors="none")}#if defined _MSC_VER || defined __WATCOMC__ || defined _WIN32{CODE}
Then open "__ogredeps/src/zziplib/CMakeLists.txt__" and change line 45 from: {CODE(wrap="1", colors="none")}if (WIN32)
add_definitions(-D_MSC_VER){CODE}
to {CODE(wrap="1", colors="none")}if (WIN32 AND BUILD_SHARED_LIBS)
add_definitions(-DZZIP_DLL)
link_libraries(zlib){CODE}
In CMake uncheck "__OGREDEPS_BUILD_OIS__"
Ogredeps should build successfully. Run the 'install' build target.
Now run the 'edit_cache' build target and change __CMAKE_BUILD_TYPE__ from "Release" to "Debug", then press generate and close CMake when it's done.
Build 'all' again and run 'install'.
Rename 'ogredeps-build/ogredeps' to 'Dependencies'.
Copy OIS includes and libs from OIS source dir to Dependencies (also the .dlls, even though we use static OIS, Ogre will want to see the .dlls because it expects dynamic OIS. Don't worry, Ogre will still link statically), make sure to follow the filesystem of the rest of the dependencies.





!III. Ogre
Download Ogre from [https://bitbucket.org/sinbad/ogre/downloads|Ogre Bitbucket repository]
From here on let's assume you extracted Ogre source to 'ogre' and use 'ogre-build' as the build directory.
Move 'Dependencies' into the 'ogre'.
To fix an Ogre bug with 64 bit MinGW, Open '__ogre/CMakeLists.txt__', find the flag '-march=i686' and change it to '-march=native'.

Download the attached '__winres.h__' file and put it in '__ogre/OgreMain/src/WIN32__' (For some odd reason it's missing from newer commits)
{ATTACH(name="winres.h",id="winres",icon="1")}{ATTACH}

In '__ogre/OgreMain/include/WIN32/OgreMinGWSupport.h__' change line 46 from: {CODE(wrap="1", colors="none")}#define WINAPI_INLINE inline{CODE}
to {CODE(wrap="1", colors="none")}#ifndef WINAPI_INLINE
#define WINAPI_INLINE inline
#endif // WINAPI_INLINE{CODE}

Then, to remove an annoying warning that pops up a lot, change: {CODE(wrap="1", colors="none")}#ifndef __uuidof(Object){CODE}
to {CODE(wrap="1", colors="none")}#ifndef __uuidof{CODE}

Now open '__ogre/OgreMain/src/WIN32/OgreMinGWSupport.cpp__' and comment out line 46 like this (it is already defined in TDM headers, multiple definitions cause errors): {CODE(wrap="1", colors="none")}//intptr_t __security_cookie;{CODE}
Then change line 48 from: {CODE(wrap="1", colors="none")}void _fastcall __security_check_cookie(intptr_t i){CODE}
to {CODE(wrap="1", colors="none")}void _fastcall __security_check_cookie(uintptr_t i){CODE}

Edit '__ogre/RenderSystems/Direct3D9/src/OgreD3D9Plugin.cpp__'.
Change line 36 from: {CODE(wrap="1", colors="none")}void _fastcall __security_check_cookie(intptr_t i);{CODE}
to {CODE(wrap="1", colors="none")}void _fastcall __security_check_cookie(uintptr_t i);{CODE}
And change line 63 from: {CODE(wrap="1", colors="none")}__security_check_cookie((intptr_t)NULL);{CODE}
to {CODE(wrap="1", colors="none")}__security_check_cookie((uintptr_t)NULL);{CODE}

Edit '__ogre/RenderSystems/Direct3D9/include/OgreD3D9Prerequisites.h__' at line 75:
Remove {CODE(wrap="1", colors="none")}#include <DxErr.h{CODE}
Add {CODE(wrap="1", colors="none")}
#include <dxerr9.h>
#define DXGetErrorDescription(hr) DXGetErrorDescription9(hr)
{CODE}

Edit '__ogre/RenderSystems/Direct3D9/src/OgreD3D9HLSLProgram.cpp__'.
At line 33 add: {CODE(wrap="1", colors="none")}#include <d3dcompiler.h>{CODE}

At line 865 (864 originally, 865 after added include) change: {CODE(wrap="1", colors="none")}
LPD3DXBUFFER pDisassembly=0;
HRESULT hr=D3DXDisassembleShader(code,FALSE,"// assemble code from D3D9HLSLProgram\n",&pDisassembly);
{CODE}
to {CODE(wrap="1", colors="none")}
LPD3DBLOB pDisassembly=0;
HRESULT hr=D3DDisassemble(code,sizeof(code),FALSE,"// assemble code from D3D9HLSLProgram\n",&pDisassembly);
{CODE}

In '__ogre/RenderSystems/Direct3D9/src/OgreD3D9RenderSystem.cpp__' change line 473 from: {CODE(wrap="1", colors="none")}d3dEx->QueryInterface(__uuidof(IDirect3D9), reinterpret_cast<void **>(&mD3D));{CODE}
to {CODE(wrap="1", colors="none")}d3dEx->QueryInterface(IID_IDirect3D9, reinterpret_cast<void **>(&mD3D));{CODE}

In '__ogre/RenderSystems/GL/src/Win32/OgreWin32Window.cpp__' change line 260 from: {CODE(wrap="1", colors="none")}+ ::Ogre::StringConverter::toString(le){CODE}
to {CODE(wrap="1", colors="none")}+ ::Ogre::StringConverter::toString(size_t(le)){CODE}

In '__ogre/Samples/EndlessWorld/include/EndlessWorld.h__' change line 143 from: {CODE(wrap="1", colors="none")}String lName = StringConverter::toString((unsigned long)(t))+"/"+"LodInfoLabel";{CODE}
to {CODE(wrap="1", colors="none")}String lName = StringConverter::toString((size_t)(t))+"/"+"LodInfoLabel";{CODE}

CMake settings:
__CMAKE_BUILD_TYPE__: (do both Release and Debug separately running install after each one, just like when building ogredeps)
Change __DirectX9_D3DX_LIBRARY__ to: __''C:/C++/TDM-4.9.2/''x86_64-w64-mingw32/lib/libd3dx9_43.a__
Change __DirectX9_DXERR_LIBRARY__ to: __''C:/C++/TDM-4.9.2/''x86_64-w64-mingw32/lib/libdxerr9.a__
Change __DirectX9_DXGUID_LIBRARY__ to: __''C:/C++/TDM-4.9.2/''x86_64-w64-mingw32/lib/libdxguid.a__
Change __DirectX9_INCLUDE_DIR__ to: __''C:/C++/TDM-4.9.2/''x86_64-w64-mingw32/include__
Change __DirectX9_LIBRARY__ to: __''C:/C++/TDM-4.9.2/''x86_64-w64-mingw32/lib/libd3d9.a__

Untick __OGRE_BUILD_PLUGIN_CG__
Untick __OGRE_BUILD_RENDERSYSTEM_D3D11__
Tick __OGRE_BUILD_RENDERSYSTEM_GL3PLUS__
Tick __OGRE_STATIC__
Now generate makefiles.

DO THIS STEP AGAIN AFTER BUILDING RELEASE (OR DEBUG) AND SWITCHING TO THE OTHER (__regenerated makefiles will reset this file__):
Edit '__ogre-build/Samples/Browser/CMakeFiles/SampleBrowser.dir/link.txt__' by adding "__-lwbemuuid -ldinput8 -ldxguid -ld3dcompiler_46__" at the end of it (we need to link against extra libs, because we use static OIS and because we included d3dcompiler in DirectX9). Sadly, DirectX is not static, so you will need to get d3dcompiler_46.dll from the Windows 8 kit bin folder.

Now after all these changes (whew!), you can finally open the project file and build Ogre. Remember to build and install both targets. When all is done, run SampleBrowser to make sure it works - if it doesn't, something went wrong in the process. If that happens, first make sure you followed all the steps carefully. If you did, post about the problem details in the forum help section.

You may delete OIS.dll and OIS_d.dll from the '__ogre-build/sdk/bin__' folder as they are not needed, OIS is static.
Because of this, you must remember to link against __wbemuuid__, __dinput8__, __dxguid__ and __d3dcompiler_46__ in your Ogre projects.

Another thing to remember is to add OgreWin32Resources.res to your projects, all static builds of Ogre need it.
{ATTACH(name="OgreWin32Resources.res",id="win32resources",icon="1")}{ATTACH}




!IV. To-do list and binaries
Known problems:
*DirectX11 render system won't compile
*Cg Program Manager plugin crashes
*Skeleton animations crash
*Improvements for the static tutorial framework could be made


[https://dl.dropboxusercontent.com/u/100767050/OGRE-1.10.0.zip|Download pre-built binaries]
        

History

Information Version
Mon 31 of Aug, 2015 07:39 GMT-0000 HackerManiac 9
Mon 06 of Apr, 2015 18:37 GMT-0000 HackerManiac 8
Mon 06 of Apr, 2015 18:36 GMT-0000 HackerManiac 7
Mon 06 of Apr, 2015 18:25 GMT-0000 HackerManiac Added a table of contents 6
Mon 06 of Apr, 2015 18:21 GMT-0000 HackerManiac Updated page according to my article on the forums 5
Sun 22 of Feb, 2015 00:09 GMT-0000 HackerManiac 4
Mon 16 of Feb, 2015 17:19 GMT-0000 HackerManiac 3
Mon 16 of Feb, 2015 17:04 GMT-0000 HackerManiac Added OgreWin32Resources.res 2
Mon 16 of Feb, 2015 17:00 GMT-0000 HackerManiac Initial wiki article - source is here: http://www.ogre3d.org/forums/viewtopic.php?f=1&t=82753 1