Codeblocks and MinGW         Using Ogre with Code::Blocks + MinGW C++ Toolbox

%prevogre%

Image

Using Ogre with Code::Blocks + MinGW C++ Toolbox


WARNINGS!
The SDK will not work with Code::Blocks 1.0 RC2. For the longest time, RC2 has been the latest release, and the advice has been to use a recent nightly build, but as of February 2008, there finally is a new official release: 8.02. If you have 1.0 RC2 or an older nightly build of Code::Blocks, do scoot over to their site and get the latest release!

The Ogre SDK for Code::Blocks + MinGW uses a modified version of MinGW called MinGW C++ Toolbox which is a complete MinGW c++ installation with all required support tools including a modified version of libstdc++.

Be sure to restart your machine after installing the Windows version of the Ogre SDK. The installer creates an OGRE_HOME environment variable, that won't be recognized by Visual Studio or Code::Blocks until after Windows XP is restarted.

Download the SDK

Ogre 1.4.0 SDK for Code::Blocks + MingW

SDK Download
NOTE: This SDK uses a modified version of libstdc++ with MingW gcc 3.4.5.
Make sure you have the latest Code::Blocks and MingW C++ Toolbox installed.
Ogre's memory manager has been turned off for debug builds.


Ogre 1.2.5 SDK for Code::Blocks + MingW

SDK Download
NOTE: This SDK uses a modified version of libstdc++ with MingW gcc 3.4.5.


Why use a modified version of libstdc++ v3 with MingW?

MingW will statically link libstdc++ (the library portion, not the STL) to each build ie each dll or exe. This creates a problem when passing strings and any stream types across dll's. Because the static linking has each copy of libstdc++ managing its own strings and streams, passing a string/stream to another dll and then having it modified there will trash memory. Ogre has several dll's and does pass strings and streams around. Do a debug build of Ogre with libstdc++ and then run in gdb and you find out quickly that a crash occurs in OgrePlatform_d.dll after the config window closes when it tries to modify/deallocate a string passed to it from OgreMain.dll.

A release build using libstdc++ "seems" to run fine for simple Ogre demos but if you start passing a lot of Ogre strings across dll's in a more complicated app, the app starts to misbehave after a while and crashes occur.

libstdc++ was rebuilt with the configure option --enable-fully-dynamic-string so that strings are dynamically allocated using the RTL and can be passed across the dll boundry.<br />


wchar, wstring and wide streams for unicode support don't work in the standard pre-built libstdc++ that comes with g++ 3.4.5. libstdc++ was rebuilt with wchar, wstring and wide stream to support wide strings so that Ogre 1.4.x could be built.

The Ogre SDK Contents:

The Ogre SDK comes with:

  • all the Ogre modules built for you ie the dll's and static archives
  • the Ogre manual in HTML format
  • API reference in the form of a windows compiled help (.chm)
  • All header files (*.h) for the libs/dll are included
  • Source code and project files for 30 demos that you can compile and run as a confidence test of the SDK installation and to see what Ogre can do.
  • All media resources required for demos
    • Material Scripts + shader programs
    • Compositor Scripts
    • Particle Scripts
    • Meshes + Animations
    • Textures

What you need to provide that is not supplied in the SDK

The SDK was built and tested with the following:

MinGW C++ Toolbox

Download the MinGW C++ Toolbox provided on the Ogre SF files site. MinGW must be setup before running Code::Blocks for the first time to make detection of MinGW go smoothly.

Download the installer package which will install the following in your mingw directory ie c:\mingw.

MinGW Toolbox Install Guide

Read the MinGW Toolbox Install Guide before running the toolbox installer.

Note:

For users migrating from CB + MinGW + STLPort to CB + MinGW there are a number of things you will have to do to ensure your project will build with Ogre SDK 1.2.x or 1.4.x and MinGW C++ Toolbox. See the [[MinGW Toolbox project migration]] page


Code::Blocks

There is an official release of Code::Blocks as of February 2008. This supersedes the previous release candidate, which even the
Code::Blocks team didn't recommend anyway. For the longest time, to use Code::Blocks you had to have a nightly build of the development trunk,
certainly so if you wanted to compile OGRE. If you have used release candidate RC2 or one of the pre-release nghtly builds, do get the
new official release instead! In any case, the build files supplied with OGRE will not work with the old release candidate.

Check Code::Blocks + MinGW installation

Make sure that Code::Blocks found your MinGW C++ Toolbox installation by following these instructions here: Code Blocks Compiler Setup

DirectX 9.0c August 2006 edition
  • . You will need the DirectX SDK if you plan to build and run in debug mode when using Direct3D9 Rendering mode. If you plan on building Ogre from source at a later date then you will need the DirectX SDK also. Note that this SDK doesnt work on Windows 2000 or less.


Note: You do not need to download the dependencies package for Code::Blocks+MingW, everything you need is included in the SDK.

Files in the Ogre 1.4.x SDK:

The Ogre Core libraries and plugins:

Debug files:
  • Ogre dll's:
    • OgreMain_d.dll
    • Plugin_BSPSceneManager_d.dll
    • Plugin_CgProgramManager_d.dll
    • Plugin_OctreeSceneManager_d.dll
    • Plugin_ParticleFX_d.dll
    • RenderSystem_Direct3D9_d.dll
    • RenderSystem_GL_d.dll
    • OgreGUIRenderer_d.dll

  • dependencies dll's:
    • cg.dll
    • CEGUIBase_d.dll
    • CEGUIFalagardWRBase_d.dll
    • CEGUITinyXMLParser_d.dll

  • static libs:
    • libode_d.a (OPCODE included in static lib)

Release files:
  • Ogre dll's:
    • OgreMain.dll
    • Plugin_BSPSceneManager.dll
    • Plugin_CgProgramManager.dll
    • Plugin_OctreeSceneManager.dll
    • Plugin_ParticleFX.dll
    • RenderSystem_Direct3D9.dll
    • RenderSystem_GL.dll
    • OgreGUIRenderer.dll

  • dependencies dll's:
    • cg.dll
    • CEGUIBase.dll
    • CEGUIFalagardWRBase.dll
    • CEGUITinyXMLParser.dll

  • static libs:
    • libode.a (OPCODE included in static lib)

Files in the Ogre 1.2.x SDK:

The Ogre Core libraries and plugins:

Debug files:
  • Ogre dll's:
    • OgreMain_d.dll
    • OgrePlatform_d.dll
    • Plugin_BSPSceneManager.dll
    • Plugin_CgProgramManager.dll
    • Plugin_OctreeSceneManager.dll
    • Plugin_ParticleFX.dll
    • RenderSystem_Direct3D9.dll
    • RenderSystem_GL.dll
    • OgreGUIRenderer_d.dll

  • dependencies dll's:
    • ilu.dll
    • devil.dll
    • cg.dll
    • zlib1.dll
    • CEGUIBase_d.dll
    • CEGUIFalagardBase_d.dll
    • CEGUITaharezLook_d.dll
    • CEGUIWindowsLook_d.dll

  • static libs:
    • libOPCODE.a
    • libode.a

Release files:
  • Ogre dll's:
    • OgreMain.dll
    • OgrePlatform.dll
    • Plugin_BSPSceneManager.dll
    • Plugin_CgProgramManager.dll
    • Plugin_OctreeSceneManager.dll
    • Plugin_ParticleFX.dll
    • RenderSystem_Direct3D9.dll
    • RenderSystem_GL.dll
    • OgreGUIRenderer_d.dll

  • dependencies dll's:
    • ilu.dll
    • devil.dll
    • cg.dll
    • zlib1.dll
    • CEGUIBase.dll
    • CEGUIFalagardBase.dll
    • CEGUITaharezLook.dll
    • CEGUIWindowsLook.dll

  • static libs:
    • libOPCODE.a
    • libode.a


Ogre 1.4.x Dependencies and their version numbers used to build the SDK:



  • CEGUI 0.5.0
  • zlib 1.2.3
  • zziplib 0.13.49
  • FreeImage 3.9.3 cvs HEAD
  • Cg 1.4.1
  • FreeType 2.3.0
  • DX9.0c SDK Aug 2006


Ogre 1.2.x Dependencies and their version numbers used to build the SDK:

  • CEGUI 0.4.1
  • zlib 1.2.3
  • zziplib 0.13.38
  • Devil 1.6.8 cvs
  • Cg 1.4.1
  • FreeType 2.1.10
  • DX9.0c SDK Aug 2006

Note: some may notice that there are very few import libs included in the SDK. This is because MingW's linker (ld) can link directly to a dll that was built by it (just like on linux with gcc(ld)). This way of linking is faster too.


Installation size is 234 Megs after the installer decompresses

Ogre SDK Installation


Before you install the Ogre SDK make sure Code::Blocks is not running. The Ogre SDK installer will set an environment variable OGRE_HOME and if Code::Blocks is running then it won't see it until the next time you run Code::Blocks. There is another way to get Code::Blocks to see the new environment variable without restarting Code::Blocks but for new users the simplest way is to not have CB running when the Ogre SDK is installed.

Run OgreSDKSetup1.4.0_CBMingW.exe which will install the Ogre SDK into c:\OgreSDK if you don't change the installation directory. The installer will create an Environment Variable called OGRE_HOME that points to the SDK installation directory. If you decide to change the SDK directory name or move the SDK after installation, make sure you update OGRE_HOME in your environment settings.

NOTE: Some people have had linker problems when the SDK is intalled in a directory that has spaces in its name so it is recommended not to install the SDK into a directory that uses spaces in its name.

After the installer finishes, you should do a confidence test to make sure MingW and Code::Blocks are setup properly. If the dev tools are setup correctly you should be able to build all the demos in debug and release with a few clicks of the mouse.

Launch Code::Blocks and then open Samples.workspace in C:\OgreSDK\Samples directory. Select build workspace in the build menu. Both debug and release targets will be built and takes about 13 minutes to do all demos on a Athlon XP 2000+ with 512Megs ram.

To run a demo within CB, right click on the demo in the project listing, then select Activate Project. You can now do Ctrl-F10 or click on the blue arrow (looks like a play button) beside the blue gear. A window will probably popup if target is set to all asking you to select Debug or release.

Setting up Project and Target Build Options in Code::blocks


Have a look at the build options for Demo_CameraTrack, most of the demos use the same build options.

Note: with MinGW gcc 3.4.5 you can link directly against dll's built by gcc 3.4.5 and do not require an import lib. This is the same setup on Linux where you link directly to the shared object (.so). This is why the SDK does not come with import libs for Ogre. You don't need them.

Build options that you should use:

Normally you will have two targets: Debug and Release.

To create a new target:

  1. Right click on the project in the Management window and select Properties in the popup and this will open up the properties window for your project.
  2. Select the Target tab.
  3. Select Add to define a new target.
  4. Type in the target name ie Debug.
  5. Select OK.


Select Build Options to modify build options for a target.

Project build options

will be used for both Debug and Release target build options:

Image

ensure Selected compiler is: GNU GCC Compiler

  • Compiler
    • Other options
      • -mthreads
      • -fmessage-length=0
      • -fexceptions
      • -fident
  • Linker
    • Other linker options:
      • -Wl,--enable-auto-image-base
      • -Wl,--add-stdcall-alias
  • Directories
    • Compiler
      • $(OGRE_HOME)\include
      • Your project include directories
    • Linker
      • $(OGRE_HOME)\bin\$(TARGET_NAME)

this is the path to OgreMain.dll or OgreMain_d.dll depending on TARGET_NAME state. $(TARGET_NAME) is a built in Code::Blocks macro that you can use in your project settings. It gives you the active project target build name.

Debug build target options:


Image

ensure Selected compiler is: GNU GCC Compiler
set Policy to 'Append target options to project options'

  • Compiler
    • '#defines'
      • WIN32
      • _DEBUG
      • _WINDOWS
  • Linker
    • Link libraries:
      • Your project dll's or static libs (.a)
      • OgreMain_d
        this is the name of the debug build of OgreMain dll.
      • OIS_d.dll
        this is the debug build of OIS found in the SDK bin folder. (needed in 1.4.0)

Release build target options:

ensure Selected compiler is: GNU GCC Compiler
set Policy to 'Append target options to project options'

  • Compiler
    • '#defines'
      • WIN32
      • NDEBUG
      • _WINDOWS
  • Linker
    • Link libraries:
      • Your project dll's or static libs (.a)
      • OgreMain
        this is the name of the release build of OgreMain dll.
      • OIS.dll
        this is the release build of OIS found in the SDK bin folder. (needed in 1.4.0)


Note: OGRE_HOME is a pre-defined environment variable setup by the SDK installer. OGRE_HOME points to the directory where the SDK is installed. You can use $(OGRE_HOME) within your build options when setting up paths to specific directories with the SDK that you will need to access.

Known bugs with SDK Demos:

  • ParticleFx demo in GL rendering has problem on ATI cards with latest catalyst driver

  • There are some memory leaks in debug builds of apps using CEGUI.

Building Ogre from source


Make sure you have the latest Code::Blocks and MingW C++ Toolbox installed.

If you decide you want to keep current with cvs and not wait for the next SDK release, get the Ogre source from cvs. Use the latest stable branch (v1-4-5 "Eihort" as of September 2007).

You need to install the DirectX SDK. Get the August 2006 edition since the dependencies contain the import libs only for this version.

Dependencies for Code::Blocks + MingW


To build the Ogre 1.4.x source, you will need to install the Ogre 1.4.x Dependencies file.
It contains all the dependencies pre-built for use with Ogre 1.4.x. It includes the debug and release import libs pre-built using the August 2006 DirectX SDK. Don't use the libs that come with MingW.

To build the Ogre 1.2.x source, you will need to install the Ogre 1.2.3 Dependencies file.
It contains all the dependencies pre-built for use with Ogre 1.2.3. It includes the debug and release import libs pre-built using the August 2006 DirectX SDK. Don't use the libs that come with MingW.


Unzip the dependencies into your Ogrenew directory.

Ogre 1.4.x Dependencies and their version numbers



  • CEGUI 0.5.0
  • zlib 1.2.3
  • zziplib 0.13.49
  • FreeImage 3.9.3 cvs HEAD
  • Cg 1.4.1
  • FreeType 2.3.0
  • DX9.0c SDK August 2006 debug and release import libs


Ogre 1.2.x Dependencies and their version numbers

  • CEGUI 0.4.1
  • zlib 1.2.3
  • zziplib 0.13.38
  • Devil 1.6.8 cvs
  • Cg 1.4.1
  • FreeType 2.1.10
  • DX9.0c SDK August 2006 debug and release import libs


Note: some may notice that there are very few import libs included in the Dependency package. This is because MingW's linker (ld) can link directly to a dll that was built by it (just like on linux with gcc(ld)). This way of linking is faster too.

Directory setup in Code::Blocks


Image

In the settings menu select Compiler and Debugger to setup the directories.

Image

Setup the include directories for the compiler.

Image

Setup the lib directories for the linker. Note that DirectX SDK lib is not used. The import libs in the Ogre dependencies will be used instead since MingW cannot link directly to the libs provided in the DirectX SDK.

Image

Include directory for windows resource compiler.

Building


To build Ogre in Code::Blocks, open the Ogre.workspace file. If you have installed or are using Code::Blocks + MinGW + STLPort, open the Ogre_stlp.workspace file.

Image

In the build menu select Build Workspace. This will build the debug and release targets of all projects listed in the workspace manager window.

The build process will take about 30 minutes on a AMD Athlon XP 2000+ with 512Megs if all projects are built.

You will (hopefully) find the newly build sample demos under:

  • ogrenew\Samples\Common\bin\Debug
  • ogrenew\Samples\Common\bin\Release

Building Ogre Core DLLs

If you don't want to build the samples choose Save Workspace as... under the file menu, enter OgreCore_stlp.workspace for the file name and save. Next, close the samples and projects in the workspace that you don't want, and save again. You can use the OgreCore_stlp workspace to re-build Ogre each time you update from CVS.

Here is an example of the minimum Ogre Core DLLs that must be built for the SDK. This assumes that you are utilizing the BSP and Octree scenemanagers, both DirectX and OpenGL renderers, CG shaders, and CEGUI.

Image

Note: Code::Blocks builds the projects in the order listed in the Manager window. Dependencies have been set up to insure that if you decide to build a demo before the core libraries, the core library projects will be built first.


Alias: Codeblocks_and_MinGW