Ogre and Visual Studio Beginners FAQ
Posted by Daniel on June 28th, 2009 | 11 Comments »
Changelog:
6th January 2010
- Updated application walkthrough for Ogre 1.7.
Overview
Howdy! This is my little FAQ and troubleshooting guide for anyone new to the Ogre engine. I will be expanding it over time to cover as many problems and questions as possible. The following assumes that you are using Visual Studio C++ 2005/2008 and have built the latest Ogre.
If you haven’t yet built Ogre, see my Building Ogre with Visual Studio guide.
Can you walk me through setting up an Ogre application?
Sure!
- Open up Visual Studio C++.
- File -> New -> Project…
- Make sure the project type is “Win32″ and the templated “Win32 Console Application” is highlighted.
- Enter the name and location of your project in the respective fields. I named mine “OgreTestProject”.
- An application wizard will pop up. Click “Application Settings” and check “Empty project” then click finish.
- Right click the “Source Files” folder in the Solution Explorer. Then Add -> New Item…
- Select “C++ File (.cpp)” and enter “main” in the Name field. Add “\src” to the end of the Location field value.
- Go to Project -> Properties.
- In the top left hand corner of the Properties window change the Configuration to “All Configurations”.
- Select General in the Configuration Properties. Copy the “Output Directory”. Select Debugging and paste this in the “Working Directory” field.
- Expand C/C++ -> General
- In the “Additional Include Directories” click the “…” button and a dialog should pop up. Again, click the “…” button, navigate to YourOgreRoot/YourBuildDir/sdk/include and select the subfolder “OGRE”. Click ok twice.
- Change the Configuration drop-down in the top left to “Debug”
- Expand Linker -> General
- In the “Additional Library Directories” navigate to YourOgreRoot/YourBuildDir/sdk/lib and select the subfolder “Debug”.
- Go to Linker -> Input
- In “Additional Dependencies” add “OgreMain_d.lib”.
- Change the Configuration drop-down in the top left to “Release”
- Go to Linker -> General
- In the “Additional Library Directories” navigate to YourOgreRoot/YourBuildDir/sdk/lib and select the subfolder “Release”.
- Go to Linker -> Input
- In “Additional Dependencies” add “OgreMain.lib”.
- Click ok.
- Enter the following code in main.cpp:
- In the toolbar at the top next to the green arrow is a drop-down list. Make sure this is set to “Debug”.
- Click the green arrow.
- Oh no! You got “This application failed to start because OgreMain_d.dll was not found. Re-installing the application may fix this problem”.
- Navigate to the location of your Ogre SDK and head to the bin folder, then the debug folder. Copy “OgreMain_d.dll”.
- Go to your project directory, there should be a new folder named “Debug” paste “OgreMain_d.dll” in there.
- Press the green arrow in Visual Studio again.
- Congratulations! You just ran your first Ogre application!
#include <Ogre.h>
int main(int argc, char* argv[])
{
Ogre::Root* root = new Ogre::Root("plugins.cfg", "ogre.cfg", "Ogre.log");
delete root;
return 0;
}
Why did my application crash?
So you’ve managed to get your application to compile, but something is wrong, it crashes when you run it! Here’s a step-by-step process to help you through it:
- Make sure your Working Directory (Project -> Properties -> Debugging -> Working Directory) is the same as your Output Directory (Properties -> General). This is a common cause of confusion, because without it set, Visual Studio cannot see any local files. This means it cannot find plugins.cfg or resources.cfg, so you might get resource or DLL not found errors.
- Make sure the compiler is set to “Debug” (the drop-down next to the green compile button in the top bar)
- The compiler will generate Debug and Release directories according to where and how your Output Directory (Project -> Properties -> General) is set (for example “.\bin\$(ConfigurationName)”). In your Debug folder you should have debug DLLs, and in the release folder you should have release DLLs. Debug DLLs commonly have the suffix _d at the end of the filename. Likewise, check that in your Debug configuration you are linking to Debug libraries with a _d suffix (Properties -> Linker -> Input -> Additional Dependencies).
- Run the application through Visual Studio (by clicking the green “Start Debugging” icon in the toolbar). Don’t run it by clicking on the exe.
- If something is wrong with your code, usually Visual Studio will point to the line that caused the crash. If this is the case, a yellow arrow pointing directly at the line means that it is that very line which caused the crash. If it is a green arrow, that means Visual Studio could only trace the crash up to that point, and the root of the crash is deeper.
- Check your stack trace. This is in a box on the bottom right named “Call Stack”. This shows the last lines the application stepped through before a crash. (Sometimes people will ask for this if you need help with a crash)
- Check the Ogre.log file for any abnormal messages like errors. This is generated in your application directory by default. Lines starting with OGRE_EXCEPTION are ones to look out for especially.
- Do you have all the required DLLs? Ogre on it’s own requires OgreMain(_d).dll, but there may be other libraries that you are linking to which the application requires. For example, if you’re using any CG shaders, make sure you have cg.dll, AND load the Plugin_CgProgramManager(_d).dll. You may use CEGUI, which requires the following: CEGUIBase(_d).dll, CEGUIExpatParser(_d).dll, CEGUIFalagardWRBase(_d).dll and OgreGUIRenderer(_d).dll. If you’re using OIS for input, you’ll need OIS(_d).dll.
- Search the Ogre forums, or Google, to see if anyone has had a similar problem.
- Post your problem in the Ogre forums. We’re happy to help. :)
Other things to check:
- Are the contents of your plugins.cfg and resources.cfg correct? Make sure the paths are correct.
- Do you have any referenced but undeclared pointers? The compiler is blind to this problem. If you have not initialised the pointer, and try to reference it, the application will crash at runtime. See here.
I get errors when compiling!
error: SomeHeader.h: No such file or directory
The compiler cannot find the header file(s) you specified. If these are library headers that it cannot find, you need to tell Visual Studio where to find them. Go to: Project -> Properties -> C/C++ -> General -> Additional Include Directories and add the include directories where the headers can be found. (In Ogre’s case that would be C:\OgreSDK\include)
fatal error LNK1104: cannot open file “SomeLibrary.lib”
Similarly, Visual Studio cannot find the file you’re trying to link against. Go to: Project -> Properties -> Linker -> General -> Additional Library Directories and add the directory where the library can be found.
error LNK2001: unresolved external symbol
These are a pain for beginners, and they look daunting. What it means is that the compiler cannot find the implementation of a function (.cpp) that was specified in a header file (.h). Your application may build fine, but when the compiler starts to pull all of the application together (linking), it spits out those errors. Almost ALWAYS, this is to do with not linking a certain library. According to what the unresolved external errors are suggesting, is the library that you need to link to. e.g. if it’s a load of Ogre functions, that means you haven’t linked to OgreMain.lib. Go to Project -> Properties -> Linker -> Input -> Additional Dependencies and add it.




11 Responses
Awesome tutorial/guide!
Hi Daniel,
I found this awesome blogpost when I was reading an old topic on the Ogre forums. For the last few weeks I’ve been busy learning C++ and trying to get some sort of basic setup. The wiki is not really clear on this point, so this is great.
Thanks and keep up the good work!
Nice FAQ.
It would be good to copy this content to the Ogre wiki. So more people find it.
Or at least add a link to a common place. But better would be to add the content.
(Maybe it’s still done – if not, please do it)
If you have questions or need help, just ask me (e.g. in Ogre Forum or by e-mail)
Greetings
Beauty
Hi Daniel,
Can this be used when one wants to work through the basic Ogre tutorials? I tried to use this code, but VC 2008 reports a lot of errors regarding ExampleApplication.h.
Does that mean I need a different setup to be able to work throug the tutorials?
Regards,
Peter
just tried this with Visual C++ 2008 Express Edition
works like a charm
thanks so much
I tried to run this Ogre Application. First I followed the instructions from Building Ogre with Visual Studio blog: http://blog.tidalware.com/2009/08/building-ogre-with-visual-studio/
In this tutorial, after the point 29(Go to your project directory, there should be a new folder named “Debug” paste “OgreMain_d.dll” in there), when I press the green arrow in Visual Studio again, I have 0 error and o warnings in VS solution but this :
First-chance exception at 0×7c812afb in TestOgre.exe: Microsoft C++ exception: Ogre::FileNotFoundException at memory location 0×0012f5b0..
The program ‘[2860] TestOgre.exe: Native’ has exited with code 0 (0×0).
I have to mention that I have Ogre 1.7 SVN – Stable – Branches
On the other hand in ogre.log I’ve got:
15:37:57: OGRE EXCEPTION(6:FileNotFoundException): ‘plugins.cfg’ file not found! in ConfigFile::load at ..\..\OgreMain\src\OgreConfigFile.cpp (line 83)
15:37:57: plugins.cfg not found, automatic plugin loading disabled.
15:37:57: *-*-* OGRE Initialising
15:37:57: *-*-* Version 1.7.0RC1 (Cthugha)
15:37:57: *-*-* OGRE Shutdown
15:37:57: Unregistering ResourceManager for type Compositor
15:37:57: Unregistering ResourceManager for type Font
15:37:57: Unregistering ResourceManager for type Skeleton
15:37:57: Unregistering ResourceManager for type Mesh
15:37:57: Unregistering ResourceManager for type HighLevelGpuProgram
15:37:57: Unregistering ResourceManager for type Material
last lines…
After I copied the plugins.cfg file from my sdk \ debug to the application debug folder I obtained the folowing in ogre.log:
….
5:44:04: Plugin successfully installed
15:44:04: Loading library .\Plugin_BSPSceneManager_d
15:44:04: Installing plugin: BSP Scene Manager
15:44:04: Plugin successfully installed
15:44:04: Loading library .\Plugin_CgProgramManager_d
15:44:04: Installing plugin: Cg Program Manager
15:44:04: Plugin successfully installed
15:44:04: Loading library .\Plugin_PCZSceneManager_d
15:44:05: Installing plugin: Portal Connected Zone Scene Manager
15:44:05: PCZone Factory Type ‘ZoneType_Default’ registered
15:44:05: Plugin successfully installed
15:44:05: Loading library .\Plugin_OctreeZone_d
15:44:05: Installing plugin: Octree Zone Factory
15:44:05: Plugin successfully installed
15:44:05: Loading library .\Plugin_OctreeSceneManager_d
15:44:05: Installing plugin: Octree & Terrain Scene Manager
15:44:05: Plugin successfully installed
15:44:05: *-*-* OGRE Initialising
15:44:05: *-*-* Version 1.7.0RC1 (Cthugha)
15:44:05: *-*-* OGRE Shutdown
15:44:05: Unregistering ResourceManager for type Compositor
15:44:05: Unregistering ResourceManager for type Font
15:44:05: Unregistering ResourceManager for type Skeleton
15:44:05: Unregistering ResourceManager for type Mesh
15:44:05: Unregistering ResourceManager for type HighLevelGpuProgram
15:44:05: Uninstalling plugin: Octree & Terrain Scene Manager
15:44:05: Plugin successfully uninstalled
15:44:05: Unloading library .\Plugin_OctreeSceneManager_d
15:44:05: Uninstalling plugin: Octree Zone Factory
15:44:05: Plugin successfully uninstalled
15:44:05: Unloading library .\Plugin_OctreeZone_d
15:44:05: Uninstalling plugin: Portal Connected Zone Scene Manager
15:44:05: Plugin successfully uninstalled
15:44:05: Unloading library .\Plugin_PCZSceneManager_d
15:44:05: Uninstalling plugin: Cg Program Manager
15:44:05: Plugin successfully uninstalled
15:44:05: Unloading library .\Plugin_CgProgramManager_d
15:44:05: Uninstalling plugin: BSP Scene Manager
15:44:05: Plugin successfully uninstalled
15:44:05: Unloading library .\Plugin_BSPSceneManager_d
15:44:05: Uninstalling plugin: ParticleFX
15:44:05: Plugin successfully uninstalled
15:44:05: Unloading library .\Plugin_ParticleFX_d
15:44:05: Uninstalling plugin: GL RenderSystem
15:44:06: *** Stopping Win32GL Subsystem ***
15:44:06: Plugin successfully uninstalled
15:44:06: Unloading library .\RenderSystem_GL_d
15:44:06: Uninstalling plugin: D3D9 RenderSystem
15:44:06: D3D9 : Shutting down cleanly.
15:44:06: D3D9 : Direct3D9 Rendering Subsystem destroyed.
15:44:06: Plugin successfully uninstalled
15:44:06: Unloading library .\RenderSystem_Direct3D9_d
15:44:06: Unregistering ResourceManager for type Material
What should I do next ?
Thank you.
Thanks!! finally. I didn’t want to resort to using CodeBlocks to use ogre. Now all i need to do is find ogre tutorials
Very nice step-by-step guide. Thanks!
@Cristi – Well then you’ve successfully loaded Ogre! Because all that little bit of code does is initialise and shutdown Ogre. You can do your own stuff now.
great!!! finally i found correct instructions. thanks a lot.
Pls, can u give the tutorial like this for connecting physics engine with ogre? ODE,Newton,Bullet or something ….
thanks. all the best!!!