History: TDM MinGW64 build guide
Source of version: 9 (current)
Copy to clipboard
{BOX(width="100%",class="Layout_box9")}{SPLIT(colsize=10%|70%)}
{IMG(src="tiki-download_file.php?fileId=2144&display",height="100",alt="GCC Logo",link="Building Ogre with boost 1.50 upwards and MinGW",imalign="left",title="Building Ogre with boost 1.50 upwards and MinGW")}{IMG}
---
{DIV(class="bigBold")}((TDM MinGW64 build guide)){DIV}
This is a guide for building Ogre and its dependencies statically, using a variation of MinGW compiler, TDM MinGW64
It covers most steps in detail, the changes you need to make to the source code so it compiles and other nifty tricks to make things work. Tested on Windows 7 x64 with Ogre 1.10.0
{SPLIT}{BOX}
{maketoc}
!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 will want to get NVidia's Cg Toolkit from: [https://developer.nvidia.com/cg-toolkit-download]
Install the package.
The toolkit is in MSVC format and sadly doesn't work with MinGW, so we will need to convert it (read further about this here: [http://www.mingw.org/wiki/msvc_and_mingw_dlls]
Download '__reimp__' tool to convert Cg libs from MSVC to MinGW format (Google will help you here).
Make a folder and call it '__converter__'.
In '__converter__' make two folders, one called '__bin__' and the other '__lib__'.
Move '__reimp.exe__' into '__converter/bin__'.
Copy '__cg.dll__' and '__cg.lib__' from Cg Toolkit's installation directory into '__converter/lib__'.
Now open notepad and save this as '__convert.bat__' (MAKE SURE THE EXTENSION IS .BAT AND NOT .TXT) in '__converter__' folder.
{CODE(wrap="1", colors="none")}set lib_file=Cg.lib
set dll_file=Cg.dll
set def_file=Cg.def
set a_file=libcg.a
cls
@echo off
cd lib
echo [ Making .DEF file ]
echo.
..\bin\reimp.exe -d %lib_file%
echo [ Making .A linker library ]
echo.
echo.
dlltool --as-flags=-64 -m i386:x86-64 --input-def %def_file% -dllname %dll_file% --kill-at --output-lib %a_file%
echo Success, now exiting.
exit{CODE}
Run '__convert.bat__' and you should find '__libcg.a__' in '__converter/lib__'. Use this instead of cg.lib in ogredeps (CMake should find it automatically, even when the names are not the same).
3. 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' folder.
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, if you use directx9 rendering, __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. Known problems:
*DirectX11 render system won't compile, it's not supported by MinGW