Compiling DX9 With MinGW

Before we start, know that this has not been extensively tested yet. I have not been able to get dx8 working with Irrlicht yet, but if I am able to do so easily I will be sure to update this tutorial.

Get DirectX SDK

You can download the latest DirectX SDK here.

if for some reason that link does not work, just google "directx sdk download"
this tutorial has been tested with d3dx9_41 (Mar09) and d3dx9_40 (Nov08)

Installing DirectX SDK

After the 500MB SDK is finally downloaded, we need to install it. And contrary to popular belief you only need a small portion of the SDK to actually build Irrlicht with DX9 support. Install wherever you like, just place it somewhere meaningful. Below are the settings you should need.

  • Install DirectX Runtime
  • Developer Runtime Support (only if you want to compile against a debug build of DirectX)
  • DirectX Headers and Libs
  • DirectX Redistributable Files (only if you want to include DirectX install with your app)

Now make sure you know the path to the install folder, default is C:\Program Files\Microsoft DirectX SDK (March 2009) If your like me and don't like the bloat, you can copy the Include and Lib folders somewhere else for better organization, and remove the SDK after that. All Irrlicht will care about is Include and Lib.

Setting up Code::Blocks

If you are not using Code::Blocks you will have to set the command line args yourself, as I have not used MinGW that way.

Open up the Irrlicht-gcc.cbp project file (or the workspace in examples).
Right-Click on the Irrlicht project in the Project Management window, and select Build Options...

Now there are a lot of build targets in here, so select one of the Win32 ones (preferably which one you want to build). After we are done you are able to copy these setting to the other build targets if you want.

First we need to tell Irrlicht we want to build with DirectX support, so we will add another line under the #defines tab.
  • IRR_COMPILE_WITH_DX9_DEV_PACK (more about this later)

Now onto the Linker setting tab! We need to tell the compiler that we want to link to DirectX9 so add another Link Library

  • d3dx9 (d3dx9d for debug build of DirectX)

Go over to the Search Directories tab next. On the Compiler tab add this, and move it to the top of the list

  • C:\Program Files\Microsoft DirectX SDK (March 2009)\Include (or click the ... to browse for it easily)

Next is the Linker tab, add the Lib folder for your system. Only x86 was tested for this.

  • C:\Program Files\Microsoft DirectX (March 2009)\Lib\x86

Redo these steps for any other build targets you want to build with DirectX support. Then click OK and move on!

Edit Irrlicht\include\IrrCompileConfig.h

This step is not needed for d3dx9_40 and _42, looks like it might just be for _41.

Around line 115 there should be this #if statement:

#if defined(_IRR_WINDOWS_API_) && (!defined(__GNUC__) || defined(IRR_COMPILE_WITH_DX9_DEV_PACK))

Remember we defined IRR_COMPILE_WITH_DX9_DEV_PACK earlier, however, the actual DevPack is for DevC++. We are not using that but we need to get around the !defined(__GNUC__) statement.

We need to define a null macro that popped its little ugly head in with the Mar09 SDK! So make the #if statement look like this:
#if defined(_IRR_WINDOWS_API_) && (!defined(__GNUC__) || defined(IRR_COMPILE_WITH_DX9_DEV_PACK))

//! Only define _IRR_COMPILE_WITH_DIRECT3D_8_ if you have an appropriate DXSDK, e.g. Summer 2004
//#define _IRR_COMPILE_WITH_DIRECT3D_8_
#define _IRR_COMPILE_WITH_DIRECT3D_9_
#define DECLSPEC_DEPRECATED

#endif

BUILD!

Make sure you select the build target you added the define and search paths to, and build Irrlicht with DirectX9 support using MinGW!

Tested Configs

C::B     MinGW        Irrlicht      DirectX
-----    ---------    ----------    ----------
8.02     3.15.2       1.5           40 (Nov08)
8.02     3.15.2       1.5           41 (Mar09)
8.02     3.15.2       1.6(r2491)    41 (Mar09)
r5716    GCC 4.4.0    1.5.1         40 (Nov08)
r5731    3.15.2       1.6 (sdk)     42 (Aug09)
8.02     3.14         1.7 (sdk)     42 (Aug09)

If you have any questions or comments about this tutorial please feel free to email me. If this does work for you and have other configs that work, please email them to me or add to the wiki.