Skip to main content

History: Setting Up An Application - CodeBlocks

Preview of version: 71

Image
Setting Up An Application With Code::Blocks And MinGW


Introduction

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 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.

Prerequisites

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: http://www.mingw.org/
For instructions on how to install MinGW go to: http://www.mingw.org/wiki/InstallationHOWTOforMinGW

Install Code::Blocks

Download the Code::Blocks official release.

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:

CodeBlocks global compiler settings

It should be populated properly, but it can't hurt to check. ๐Ÿ˜Š

Also make sure that the MinGW version Code::Blocks uses is the same that was used to compile the Ogre SDK (it is written in the SDK downloads section). Or at least compatible.
1.8.1 was compiled with GCC 4.7.0, but also seems to run fine if you use it with GCC 4.7.2.

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':

newProject.png

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

projectPaths.png


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:

newFilesinFolder.png

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...:

addFilesRecursively1.png

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

addFilesRecursively2.png


Project Build Options

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

gotoBuildOptions.png

Common Build Options

Compiler settings - Other options


Set Compiler settings - Other options to

Copy to clipboard
-mthreads -fmessage-length=0 -fexceptions -fident


projectSettings1.png

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

Compiler settings - defines


Set Compiler settings - defines to

Copy to clipboard
WIN32 _WINDOWS


projectSettings2.png

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

Copy to clipboard
-Wl,--enable-auto-image-base -Wl,--add-stdcall-alias -Wl,--enable-auto-import


projectSettings3.png

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

Search Directories - Compiler


Set Search Directories - Compiler to

Copy to clipboard
$(OGRE_HOME)\include $(OGRE_HOME)\include\OGRE $(OGRE_HOME)\include\OIS $(OGRE_HOME)\boost


Code::Blocks Search Directories

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

Copy to clipboard
$(OGRE_HOME)\bin\$(TARGET_NAME)


projectSettings5.png

Again, you need to have OgreProject selected, not one of the build configurations! ๐Ÿ˜›

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

Copy to clipboard
_DEBUG


projectSettings6.png



Set Debug - Linker settings - Link libraries to

Copy to clipboard
OgreMain_d OIS_d


projectSettings7.png


Release Build options

Release - Compiler settings - defines


Set Release - Compiler settings - defines to

Copy to clipboard
NDEBUG


projectSettings8.png



Set Release - Linker settings - Link libraries to

Copy to clipboard
OgreMain OIS


projectSettings9.png


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:

Copy to clipboard
date_time thread system chrono

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.

Debugging

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:

code_blocks_build_targets_dialog.png


Conclusion

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. ๐Ÿ˜Š

History

Information Version
Sat 08 of Aug, 2015 17:36 GMT-0000 spacegaier fixed broken link 76
Mon 04 of Mar, 2013 08:21 GMT-0000 TheSHEEEP 75
Mon 04 of Mar, 2013 08:19 GMT-0000 TheSHEEEP Added more clear filename explanation. 74
Thu 13 of Dec, 2012 16:37 GMT-0000 Flateno Added a hint to include linker lib path for boost 73
Wed 07 of Nov, 2012 08:39 GMT-0000 TheSHEEEP 72
Wed 07 of Nov, 2012 08:36 GMT-0000 TheSHEEEP 71
Wed 07 of Nov, 2012 08:35 GMT-0000 TheSHEEEP 70
Wed 07 of Nov, 2012 08:35 GMT-0000 TheSHEEEP 69
Wed 07 of Nov, 2012 08:35 GMT-0000 TheSHEEEP Added info for boost 68
Wed 07 of Nov, 2012 08:28 GMT-0000 TheSHEEEP Added some help to prevent MinGW GCC version confusion. 67
Wed 07 of Nov, 2012 08:26 GMT-0000 TheSHEEEP 66
Fri 08 of Jun, 2012 03:47 GMT-0000 jacmoe 65
Fri 25 of May, 2012 23:56 GMT-0000 jacmoe Boost version is no longer part of directory name 64
Sun 28 of Aug, 2011 00:56 GMT-0000 jacmoe 63
Wed 09 of Feb, 2011 02:34 GMT-0000 Lexi changed boost link to 1_44 and under Release defines corrected tab title from Debug ... to Release ... Copy Paste issue i think 62
Sun 26 of Dec, 2010 16:34 GMT-0000 grimfang4 Added specific mention of resources.cfg and plugins.cfg, since they're what I additionally needed when I followed these directions. 61
Sun 19 of Dec, 2010 20:58 GMT-0000 calipe OGRE 1.7.2 requires the latest MinGW distribution. The old version of this article instructed the users to download the TDM MinGW suit which installs MinGW 4.4.1; this leads to linking errors when com 60
Fri 27 of Aug, 2010 02:04 GMT-0000 UnknownDevice Changed link from nightly build to main binaries as they been updated to 10.05 as of 27 May 2010 59
Tue 03 of Aug, 2010 13:16 GMT-0000 enclave 58
Tue 03 of Aug, 2010 12:28 GMT-0000 enclave Changed search directories: $(OGRE_HOME)\include\boost_1_42 -> $(OGRE_HOME)\boost_1_42. Because this path doesn't exists and causes compilation errors. 57
Thu 27 of May, 2010 14:17 GMT-0000 jacmoe 56
Thu 27 of May, 2010 14:16 GMT-0000 jacmoe 55
Thu 27 of May, 2010 14:16 GMT-0000 jacmoe 54
Sun 23 of May, 2010 00:08 GMT-0000 jacmoe 53
Sun 23 of May, 2010 00:08 GMT-0000 jacmoe 52