Setting Up An Application With Code::Blocks And MinGW


This set of instructions will walk you through setting up a Code::Blocks C++ project from scratch. An alternative to this tutorial is to use the Ogre Application Wizard(external link) instead. This tutorial is still useful if you wish to understand what the Application Wizard does for you. When you have finished this tutorial you will be able to compile a working Ogre Application and you will be ready to start the Basic Tutorials.


Install the Ogre SDK as detailed here: Installing the Ogre SDK
note Make sure that the environment variable OGRE_HOME is pointing to the root of the Ogre MinGW SDK.

Setting up Code::Blocks / MinGW for OGRE Development

Install the latest MinGW official distribution

OGRE 1.7.2 requires MinGW 4.5. Get it at: link)
For instructions on how to install MinGW go to: link)

Install Code::Blocks

Download the Code::Blocks official release(external link).
It is suggested to download the version that does not come with its own version of MinGW, as it might be incompatible with the one used to compile the Ogre SDK.

Create a directory for it - C:\CodeBlocks - and unzip the three archives into it.

Start Code::Blocks and pick the MinGW compiler from the list of detected build systems.

Goto Settings -> Compiler and Debugger to show the Global compiler settings:


It should be populated properly, but it can't hurt to check. smile

Also make sure that the MinGW version Code::Blocks uses is the same that was used to compile Ogre.
Do not use the MinGW version that comes with Code::Blocks. It is rather old.

You can find out your version of MinGW by going to "C:\MinGW\lib\gcc\mingw32".
This folder will contain another folder with a version number.

Create new Console application project

Click the 'Create a new project' link in the Code::Blocks start page, or find it in the menu.
Choose 'Console application':


Be sure to put the project in a directory with no spaces in the (full) name.
A good name would be 'C:\Projects\OgreProject':


Add the Wiki Tutorial Framework

Now we need to add some files to the project.
Download the Ogre Wiki Tutorial Framework: No such attachment on this page.
Unpack the four files into your new OgreProject directory:


Right-click main.cpp in the project tree and delete it.
Now, we need to add the wiki tutorial framework to our project.
Right-click and Add files recursively...:


You are given a list of four files. Click 'OK' to add them:


Project Build Options

Right-click our OgreProject and choose Build options from the context menu:


Common Build Options


Compiler settings - Other options

Set Compiler settings - Other options to



Make sure that OgreProject is selected, and not one of the build configurations.

Compiler settings - defines

Set Compiler settings - defines to



Again, make sure that OgreProject is selected, and not one of the build configurations.

Linker settings - Other linker options

Set Linker settings - Other linker options to



Again, make sure that OgreProject is selected in the configuration tree.

Search Directories - Compiler

Set Search Directories - Compiler to



It would be prudent to mention that OgreProject should be selected in the configuration tree (and not one of the build configurations)

Search Directories - Linker

Set Search Directories - Linker to



Again, you need to have OgreProject selected, not one of the build configurations! razz

Debug Build options

Select the Debug build configuration in the configuration selector on the left.

Debug - Compiler settings - defines

Set Debug - Compiler settings - defines to




Set Debug - Linker settings - Link libraries to




Release Build options

Release - Compiler settings - defines

Set Release - Compiler settings - defines to



Set Release - Linker settings - Link libraries to



Additional libraries when using boost

When you use a version of the Ogre SDK that uses boost, you will need to link against some boost libraries.
For boost 1.50+, these are:


For previous boost versions, you can ignore system and chrono.

To get the exact file names, have a look at your Ogre SDK folder. If it uses boost, it will contain a "boost" folder which has all needed libraries in "lib" in both debug and release. (Remember to add "$(OGRE_HOME)\boost\lib" to "Search Directories - Linker" if you use boost!)

One filename could be, for example, "libboost_date_time-mgw47-mt-1_51.a", which is a boost 1.51 version compiled with MinGW GCC 4.7.X.
For this, you would have to link against "boost_date_time-mgw47-mt-1_51".



If you want to run your executable from within Code::Blocks, you need to set up 'working directory' and 'command' in the project settings like this:



That's it.
You should now be able to compile and run your Ogre application.
Well, maybe not until you've copied it to the Ogre sdk bin directory (or take resources.cfg and plugins.cfg from there).
Or by copying Ogre dlls and media..
But that's something for a later wiki article..

Proceed to the Tutorials. smile

Contributors to this page: spacegaier6073 points  , UnknownDevice101 points  , TheSHEEEP801 points  , Lexi31 points  , jacmoe180265 points  , grimfang4107 points  , Flateno786 points  , enclave303 points  , Emmentaler2437 points  and calipe97 points  .
Page last modified on Saturday 08 of August, 2015 17:36:55 UTC by spacegaier6073 points .

The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.