Setting up OGRE 3D with Code::Blocks on Mac OS X

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
elegant
Gnoblar
Posts: 16
Joined: Wed Nov 05, 2008 1:17 am
Contact:

Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by elegant »

Hi Folks,

I'm new to OGRE (Game Programming at all) and I want to setup OGRE with Code::Blocks on Mac OS X.

I downloaded the latest prebuilt SDK (1.6.1) + latest Code::Blocks (8.02-p2) for OS X.
Then Copied C::B to /Developer/Applications, and OGRE SDK to /Developer.

I open Samples.xcodeproj with Xcode and build all the bundled samples. Most of them runs and works fine.
The included readme says: for size reasons, these examples using relative folder structure to find and load there dependencies. and there is no need to copy them into /Library/Frameworks anymore (If you copy the binary (bundled .app) file to other place it crashes, because of dependencies lack).
Getting Started

This distribution contains the precompiled SDK release of OGRE for Mac OS X. Just drag the 'OgreSDK' folder to the location on your drive where you want to install the SDK. Please do drag the entire folder rather than opening it and copying any subfolders, since the internal folder structure is relevant when building the samples.

Important:If you have used a previous version of OGRE, make sure you remove Ogre.framework, CEGUI.Framework, Cg.framework and OgreCEGUIRenderer.framework from your /Library/Frameworks folder or any other 'root' folder. From version 1.4.5, all frameworks are referenced and deployed locally which is much more flexible when dealing with multiple versions, and also reflects how you would want to deploy an end application (see below).
I did not like Xcode and I planned to use Eclipse/CDT with OGRE, but found C::B is more faster, efficient and reliable C++ IDE. Since it has "Ogre Project" template, I thought configuring project became more easier.
But when I fire up C::B and create an new Ogre Project, It asked me for SDK and It has two options (the first one is hidden, I scrolled up suddenly, then it appears, maybe it refers to wxWidgets problem on OS X):

Code: Select all

"I have a folder with the OGRE source code"
"I have installed a pre-made OGRE SDK"
Then no matter I select which one, It never asks for folder that contains OGRE source code or prebuilt SDK.

It generates a main.cpp file that contains an sample application (exactly like generated code from Visual C++ OGRE wizard plug-in). When I build the project it gives me a bunch of errors like this:

Code: Select all

||=== ogreTest, Debug ===|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|5|error: Ogre.h: No such file or directory|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|12|error: ExampleApplication.h: No such file or directory|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|52|error: windows.h: No such file or directory|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|23|error: expected class-name before '{' token|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp||In member function 'void SampleApp::createScene()':|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|35|error: 'mSceneMgr' was not declared in this scope|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|38|error: 'Light' was not declared in this scope|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|38|error: 'myLight' was not declared in this scope|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|39|error: 'Light' is not a class or namespace|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|39|error: 'LT_POINT' was not declared in this scope|
/Users/msbabaei/Desktop/ogreProjects/ogreTest/main.cpp|53|error: 'INT' does not name a type|
||=== Build finished: 10 errors, 0 warnings ===|
I think it looks for SDK in a common path like /Library/Frameworks or /System/Library/Frameworks, etc. Then can't locate it there. I'm not familiar with C::B as Eclipse. No matter how hard I tried, I can't figured it out how introduce the SDK to C::B.

I think there's must be a way to apply this on a single project or IDE itself.

Any help would be appreciated!

didito
Gnoblar
Posts: 13
Joined: Tue Dec 18, 2007 12:49 pm
Location: Barcelona, Spain
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by didito »

hi.

i got it to run with codeblocks after applying some settings in the cbp-file (it is xml).
if you still need it, i can post the content of my file...

regards

User avatar
elegant
Gnoblar
Posts: 16
Joined: Wed Nov 05, 2008 1:17 am
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by elegant »

Hi, thanks for reply!

Yes, you rock! I did not know cbp files are in xml format.

I goto Windows and Codeblock wizard works fine. It ask for OgreSDK folder then it set project settings. I copied the XML code inside the cbp files and adopt it to cbp file on Mac OS X. After that when I go to Search directories tab on Project's build options the settings on xml file were applied here.

Many of errors are gone. but gcc give me the bunch of new errors.
Not from my code. It's from Ogre header files.

For example in OgreTimerImp.h
#include <Ogre/OgrePrerequisites.h>
the gcc produce this error:
/Developer/OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers/OSX/OgreTimerImp.h|33|error: Ogre/OgrePrerequisites.h: No such file or directory|

The problem is there is no Ogre directory in Headers directory and both these hear files are in the same level.
or for example OIS directory is not in the Header directory (in windows they all in include directory)
it's in
/Developer/OgreSDK/Dependencies/include

The path is different from windows but code and paths in the headers are like windows :roll:

I think I must change the ogre header files!!!
Maybe I'll try that!

didito
Gnoblar
Posts: 13
Joined: Tue Dec 18, 2007 12:49 pm
Location: Barcelona, Spain
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by didito »

hi.

don't mess with the headers! you don't need to.
it is true, there is NO "Ogre" folder for the headers,
but there is a "Headers" folder inside the Ogre.framework folder.
Frameworks (and the way GCC deals with them) are very special in MacOSX.
when you include something with these (< and >) brackets, i.e. #include <Frameworkname/blah.h>
the first part defines the framework name, not an actual folder like with "" (#include "foldername/file.h").
there are some links about this topic on the apple developer pages. it is a bit confusing at first, but really simple.

for the special apple version of GCC you need to pass these frameworks as extra parameters (-F switch), not only the search directories
for headers and library files. for normal libraries you pass them as usual (with the -I and -L switch).

so i added these switches to my codeblocks project file.
most important are my global compiler (for debug and release configuration) settings

Code: Select all

<Add option="-F../OgreSDK/Dependencies" />   ... for all the Frameworks of Ogre (Ogre itself, CEGUI, Cg)

and

<Add directory="../OgreSDK/Dependencies/include" /> ... for OIS (it is not a framework, just an ordinary library)
and my global linker settings

Code: Select all

<Add option="-F../OgreSDK/Dependencies" />   ... for all the Frameworks of Ogre (Ogre itself, CEGUI, Cg)
<Add option="-framework Ogre" />   ... link with Ogre framework
<Add option="-framework Carbon" />   ... link with Apple Carbon framework
<Add option="-framework IOKit" />   ... link with Apple IOKit framework
<Add option="-framework OpenGL" />    ... link with Apple OpenGL framework
<Add library="stdc++" />
<Add library="ois" />   ... link with OIS library
<Add directory="../OgreSDK/Dependencies/lib/Release" />

here is the full project file, take a look:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="Demo1" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="../bin/Demo1_d" prefix_auto="1" extension_auto="1" />
				<Option working_dir="../bin" />
				<Option object_output="../build/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-w" />
					<Add option="-Wall" />
					<Add option="-g" />
					<Add option="-v" />
					<Add option="-fexceptions" />
					<Add option="-DDEBUG" />
					<Add option="-D_DEBUG" />
				</Compiler>
				<Linker>
					<Add option="-g" />
					<Add option="-Wall" />
					<Add directory="../build/Debug" />
				</Linker>
			</Target>
			<Target title="Release">
				<Option output="../bin/Demo1" prefix_auto="1" extension_auto="1" />
				<Option working_dir="../bin" />
				<Option object_output="../build/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O3" />
					<Add option="-DNDEBUG" />
				</Compiler>
				<Linker>
					<Add option="-s" />
					<Add directory="../build/Release" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-march=prescott" />
			<Add option="-Wfatal-errors" />
			<Add option="-W" />
			<Add option="-arch i386" />
			<Add option="`pkg-config --cflags OGRE`" />
			<Add option="-fvisibility=default" />
			<Add option="-F../OgreSDK/Dependencies" />
			<Add option="-D__MACOSX_CORE__" />
			<Add option="-D__APPLE_CC__" />
			<Add directory="/usr/include" />
			<Add directory="/usr/include/GL" />
			<Add directory="../OgreSDK/Dependencies/include" />
		</Compiler>
		<Linker>
			<Add option="-arch i386" />
			<Add option="-march=prescott" />
			<Add option="`pkg-config --libs OGRE`" />
			<Add option="-F../OgreSDK/Dependencies" />
			<Add option="-framework Ogre" />
			<Add option="-framework Carbon" />
			<Add option="-framework IOKit" />
			<Add option="-framework OpenGL" />
			<Add library="stdc++" />
			<Add library="ois" />
			<Add directory="../OgreSDK/Dependencies/lib/Release" />
		</Linker>
		<Unit filename="../src/Demo1.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


i also post my directory layout so that you can see how it works and where i have my files:

Code: Select all

WorkingCopy
	- bin   (output folder for built executable binaries and the ogre configuration- log- and data-files)
	- build
		- Debug   (built object files for Debug configuration)
		- Release   (built object files for Release configuration)
	- Frameworks   (need all the Ogre Frameworks with its dynamic libraries here to run the built binary, copy from OgreSDK!!!)
		- CEGUI.framework
		- Cg.framework
		- Ogre.framework
	- OgreSDK   (here is my prebuilt, installed Ogre SDK with all its files, downloaded from here)
		- build   (not important for my project)
		- Dependencies   (important!!! here are my frameworks and libraries for building)
		- docs   (not important for my project
		- Samples   (not important for my project
	- prj   (here stays my codeblocks project file)
	- src   (here stays my personal sourcecode - Demo1.cpp, etc)
voila, hope this helps!!!

User avatar
elegant
Gnoblar
Posts: 16
Joined: Wed Nov 05, 2008 1:17 am
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by elegant »

Thanks to your reply.

You always ROCK!!!

I used your directory structure and your codeblocks project file plus adding these two lines.

Code: Select all

			<Add directory="../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers" />
			<Add directory="../OgreSDK/Samples/include" />
	</Compiler>
These all tips & tweaks resolved all my problems :wink: . but I still get the following error :( :

Code: Select all

||=== Demo1, Debug ===|
../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers/OgreWindowEventUtilities.h|159|error: 'EventHandlerCallRef' has not been declared|
||=== Build finished: 1 errors, 0 warnings ===|
I must mention I'm using the example code generated bye Code::Blocks Ogre Wizard. I used the SDK version 1.6.1.

didito
Gnoblar
Posts: 13
Joined: Tue Dec 18, 2007 12:49 pm
Location: Barcelona, Spain
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by didito »

good to hear that you are making some progress.

hmm, i did not need to include the ../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers
in the options since it is automatically included with the framework option.

i had the error with EventHandlerCallRef too, but i can't remember now, how i solved it.
it was very easy i think. did you include the Carbon framework? i think this fixed it ...

User avatar
elegant
Gnoblar
Posts: 16
Joined: Wed Nov 05, 2008 1:17 am
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by elegant »

I must add ../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers and ../OgreSDK/Samples/include, because It's looking for Ogre.h and ExampleApplication.h:

Code: Select all

/Users/msbabaei/Desktop/Ogre/src/Demo1.cpp|5|error: Ogre.h: No such file or directory|
/Users/msbabaei/Desktop/Ogre/src/Demo1.cpp|12|error: ExampleApplication.h: No such file or directory|
/Users/msbabaei/Desktop/Ogre/src/Demo1.cpp|52|error: windows.h: No such file or directory|
/Users/msbabaei/Desktop/Ogre/src/Demo1.cpp|23|error: expected class-name before '{' token|
||=== Build finished: 4 errors, 0 warnings ===|

Yes, I added carbon. This is my project file (I think I did not change that execpet adding two above directories)
maybe somethings wrong with that:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="Demo1" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="../bin/Demo1_d" prefix_auto="1" extension_auto="1" />
				<Option working_dir="../bin" />
				<Option object_output="../build/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-w" />
					<Add option="-Wall" />
					<Add option="-g" />
					<Add option="-v" />
					<Add option="-fexceptions" />
					<Add option="-DDEBUG" />
					<Add option="-D_DEBUG" />
				</Compiler>
				<Linker>
					<Add option="-g" />
					<Add option="-Wall" />
					<Add directory="../build/Debug" />
				</Linker>
			</Target>
			<Target title="Release">
				<Option output="../bin/Demo1" prefix_auto="1" extension_auto="1" />
				<Option working_dir="../bin" />
				<Option object_output="../build/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O3" />
					<Add option="-DNDEBUG" />
				</Compiler>
				<Linker>
					<Add option="-s" />
					<Add directory="../build/Release" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-march=prescott" />
			<Add option="-Wfatal-errors" />
			<Add option="-W" />
			<Add option="-arch i386" />
			<Add option="`pkg-config --cflags OGRE`" />
			<Add option="-fvisibility=default" />
			<Add option="-F../OgreSDK/Dependencies" />
			<Add option="-D__MACOSX_CORE__" />
			<Add option="-D__APPLE_CC__" />
			<Add directory="/usr/include" />
			<Add directory="/usr/include/GL" />
			<Add directory="../OgreSDK/Dependencies/include" />
			<Add directory="../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers" />
			<Add directory="../OgreSDK/Samples/include" />
		</Compiler>
		<Linker>
			<Add option="-arch i386" />
			<Add option="-march=prescott" />
			<Add option="`pkg-config --libs OGRE`" />
			<Add option="-F../OgreSDK/Dependencies" />
			<Add option="-framework Ogre" />
			<Add option="-framework Carbon" />
			<Add option="-framework IOKit" />
			<Add option="-framework OpenGL" />
			<Add library="stdc++" />
			<Add library="ois" />
			<Add directory="../OgreSDK/Dependencies/lib/Release" />
		</Linker>
		<Unit filename="../src/Demo1.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>
Moreover when I compile in Release mode, it's give a bunch of warnings:

Code: Select all

:1|1|warning: "__APPLE_CC__" redefined|
:1|1|warning: this is the location of the previous definition|
../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers/OgreUTFString.h|290|warning: base class 'class Ogre::UTFString::_base_iterator' should be explicitly initialized in the copy constructor|
../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers/OgreUTFString.h|421|warning: base class 'class Ogre::UTFString::_base_iterator' should be explicitly initialized in the copy constructor|
../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers/OgreUTFString.h|569|warning: base class 'class Ogre::UTFString::_base_iterator' should be explicitly initialized in the copy constructor|
../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers/OgreUTFString.h|678|warning: base class 'class Ogre::UTFString::_base_iterator' should be explicitly initialized in the copy constructor|
../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers/OgreWindowEventUtilities.h|159|error: 'EventHandlerCallRef' has not been declared|
||=== Build finished: 1 errors, 6 warnings ===|

User avatar
elegant
Gnoblar
Posts: 16
Joined: Wed Nov 05, 2008 1:17 am
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by elegant »

Oh, Sorry I'm stupid!
I did not read your post with enough accuracy.

I add this line and it compiled successfully

Code: Select all

#include <Carbon/Carbon.h>

Thank you, again.

didito
Gnoblar
Posts: 13
Joined: Tue Dec 18, 2007 12:49 pm
Location: Barcelona, Spain
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by didito »

great!

i think you don't need the Ogre.framework/Headers ... in the settings if you include ogre headers in your code like that.

Code: Select all


#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include <Ogre/Ogre.h>
#include <Ogre/OgreBlahblahblahblahblah.h>
#else
#include "Ogre.h"
#include "OgreOgreBlahblahblahblahblah.h"
#endif

on mac framework includes are defined with these symbols < >, and normal includes with " ".
if you include with the normal " " then it only looks in the supplied search directories.
more precise information here:
http://gemma.apple.com/documentation/Ma ... works.html
http://developer.apple.com/tools/gcc_overview.html

User avatar
elegant
Gnoblar
Posts: 16
Joined: Wed Nov 05, 2008 1:17 am
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by elegant »

ThanX for your consideration!

Yes it worked :wink: without adding headers path to project settings when you add the framework name in <>.

I think I must keep following information on developer.apple.com before going further. because I have lack of knowledge on developing apps for OSX.

didito
Gnoblar
Posts: 13
Joined: Tue Dec 18, 2007 12:49 pm
Location: Barcelona, Spain
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by didito »

don't worry. i also had a hard time when i started with my mac ... :)

User avatar
tone
Halfling
Posts: 64
Joined: Thu Mar 09, 2006 8:18 pm
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by tone »

I am not reading you clearly on this.

I have the
../OgreSDK/Dependencies/Ogre.framework/Versions/A/Headers/OgreWindowEventUtilities.h|158|error: 'EventHandlerCallRef' has not been declared|

error. How do I resolve this?

You say you added "#include <Carbon/Carbon.h>" and it compiled successfully, but to which file? Where in the file?

tone

User avatar
elegant
Gnoblar
Posts: 16
Joined: Wed Nov 05, 2008 1:17 am
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by elegant »

Sorry!! Couple of weeks ago I formatted my MBP and replaced dual boot Mac OS X / Windows with my dearest Gentoo (as I enjoyed it for near a year on my PC, Finally I preferred GNU/Linux over Windows and Mac OS X. At this moment I'm very happy because of this pure fREEDOM. :)

Now I have Ogre/Code::Blocks/g++ combination on GNU/Linux.

But if I remembered correctly I think you must add it to main.cpp, Sorry I have no access to Mac OS X anymore.

But if you already solved this, we will be glad to hear the solution from you here. May be it's useful to the others. At that moment I focused on my problem and I didn't predict it's useful to anyone. Sorry for that.

didito
Gnoblar
Posts: 13
Joined: Tue Dec 18, 2007 12:49 pm
Location: Barcelona, Spain
Contact:

Re: Setting up OGRE 3D with Code::Blocks on Mac OS X

Post by didito »

sorry tone, i can't quite remember. i've changed my code since then a lot.
i think it was in the main.cpp of my small demo then.

i personally always aim for every file being compilable for itself so i include just the needed headers and not some include-all kind of headerfile.
you could track down where "OgreWindowEventUtilities.h" gets included and then put in a

Code: Select all

#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include <Carbon/Carbon.h>
#endif
don't forget to include the carbon framework the macish way (described before).

Post Reply