Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build OGRE on Windows using Visual Studio?

Hope that this helps a lot of people who struggle with installing OGRE on Windows. I did, and I don't want anyone else to go through the same amount of torture.

I've tried to make this explanation different by explaining a lot more steps and details than are explained in other websites. Problems and solutions that others wouldn't have even thought of recording.

like image 656
Nav Avatar asked Oct 15 '11 08:10

Nav


1 Answers

The normal way to build Ogre from source:

Get a new self extractor of Ogre (these instructions are for Ogre version 1.7.3)
Download and install CMake
Download and install the DirectX SDK
Create a folder named "OGRE", in a drive that has at least 4.3GB of space.
Extract the ogre source into OGRE folder. Download the Ogre dependencies and extract them to the OGRE folder. Run CMake and select Visual Studio 10 as your default compiler.
Specify the source directory of Ogre. It's the ogre_src_v1-7-3 folder. Also set the OGRE_HOME environment variable in windows to the full path of ogre_src_v1-7-3. (set it by right-clicking on my computer, properties, advanced, environment variables, user variables, new) Specify a directory for CMake to place the binaries it creates. You can create a directory named 'Binaries' in OGRE folder.
Press 'configure' in CMake.
It will show a lot of red lined entries. For the OGRE_DEPENDENCIES_DIR entry, specify the path to the dependencies folder that you extracted above.
Click on 'configure' again and all those red lines will become white, which means the configuring worked fine.
Click on 'generate'.
That's it with CMake.
Go to the binaries folder, and you'll see OGRE.sln. Double click it to open it in VS2010.
Either right-click the "ALL-BUILD" project and build or press F5 (if you press F5, then when the build completes, it'll say that it can't run, which is ok, because all build isn't meant to run)
The build process should take about 30min on a dual core 2GHz PC with 1GB RAM.
Set the 'Sample browser' project as the active project and press F5 to run it.
That's it! Ogre is configured on your system.

======================================================

But if you had build problems:

To avoid a lot of problems, make sure you get your Ogre source code as a pristine folder/zip-file/self-extractor from the internet, and have DirectX SDK installed on your machine. Make a folder on your system for Ogre and store the source code folder there. When completed, the Ogre source, binaries and built files will totally occupy about 4.3GB of disk space.

[Caution: Don't install visual studio 2008 on your system. If you did, and if it causes problems (fatal error C1902: Program database manager mismatch; please check your installation) while building ogre.sln, just delete the mspdb100.dll file if you're building with VS2010. (It hasn't been confirmed if the problem is really because of installing VS2008. It may be because of one step written in this very file, where mspdb100.dll is copied into a folder where it shouldn't be. In case you're building Ogre with VS2008, and it shows the "fatal error", then deleting mspdb80.dll is the solution)]

Extract the Ogre source onto a folder in your system. It's nice to have a directory path like:
"your-root\Ogre\Binaries\" for the binaries
and
*"your-root\Ogre\ogre_src_v1-7-3\"* for the source

CMake:
Download and install CMake, which helps in configuring Ogre for installation into your system.
Run the CMake executable.
Choose "add cmake to system PATH for current user."
Find the place where cmake got installed, and run \CMake 2.8\bin\cmake-gui.exe
Specify the directories for binaries and source.
Click the "advanced" checkbox on the CMake GUI
Set CMAKE_CXX_COMPILER to your-Visual-Studio-installation-path/VC/bin/cl.exe
Set CMAKE_C_COMPILER to your-Visual-Studio-installation-path/VC/bin/cl.exe
Set CMAKE_RC_COMPILER to whatever-path-your-RC.exe-file-is-in/RC.Exe (do a search in the "Program files" folder and you're likely to find rc.exe)
Click "configure" and it may gave an error that it couldn't find mspdb100.dll
Copy mspdb100.dll from your-Visual-Studio-installation-path\Common7\IDE and paste it in your-Visual-Studio-installation-path\VC\bin (not the right way to do it, but well...; This file you later may have to delete, if during the build process of Ogre, an error like 'program database manager mismatch is shown')
Once configuration is done, click 'generate' which will generate either the ogre.sln file or a ".dsw" file which when you click, your ogre.sln file will get created. More info further on below.
Note: Cmake maintains a cache. To reconfigure cmake anytime, you have to clear the cache. Cmake 2.8 has the option for cache clearing in the menu. If you install cmake 2.6.4, you will be able to clear the cache with a button at the bottom of the window. Once you clear the cache, you'll be able to select your compiler. I chose VS2006 and didn't change any option for the native compiler. Just left it as it was.
Note2: When I installed Visual C++ 2006 the C and C++ compilers now are able to compile a test file of cmake, but cmake can't find a certain dll which is located in the bin folder of ogre_src_v1-7-3. It was looking in the \tpcsed.com\projectshare\mapex\OGRE3D folder, so I copied the bin folder into the \tpcsed.com\projectshare\mapex\OGRE3D folder. Everything ran fine then.

In case your Visual Studio version isn't able to achieve the configuration described above, you may have to install VS2006 to be able to specify the correct c1.exe and rc.exe files. VS2010's c1.exe and rc.exe's didn't work for me.

To compile any dependencies:
Extract OgreDependencies_MSVC_20101231.zip Goto your-root\Ogre\ogre_src_v1-7-3\Dependencies\src Open OgreDependencies.VS2010.sln with VS2010 (or the sln file corresponding to your VS) Right click on the solution and build the solution for debug and release (Right click solution > properties > configuration > configuration manager button > active solution configuration combobox)

Building Ogre:
Click the your-root\Ogre\ogre_src_v1-7-3\bin\ogre.dsw file and make sure it opens in the VS version you're using. In my case it was VS2010 (if you used VS2006 in CMake, you'll have a dsw file which will convert the solution to your version of VS)
An ogre.sln file will get created. Double click it.
Right click the ALL_BUILD project and click Build. You're supposed to this for both Release and Debug, but doing it for debug was enough for me (for the time being).
Right click the INSTALL project and click Build. You're supposed to this for both Release and Debug, but doing it for debug was enough for me (for the time being).
Either do the above 2 steps or simply click clean and build the entire solution.
If you find errors, search for the projects where the build failed, read the errors and correct it. All projects have to build successfully at least for debug.

If the builds fail then clean the projects and re-build. Or start again from the cmake step.
If there are build errors, find out why it's happening by looking at the errors listed. It may be because you didn't install DirectX SDK on your system or because you specified some path incorrectly in the ogre.sln projects properties. Check all values to see if all paths are correct.
That's it!

The optional dependencies like TBB, Boost etc. I didn't try to install. Ogre works without it.

Running:
Try a small Ogre app. The simplest one you should be able to get running is:

#include <Ogre.h>
//code is from http://blog.tidalware.com/2009/06/ogre-and-visual-studio-beginners-faq/
int main(int argc, char* argv[])
{
    Ogre::Root* root = new Ogre::Root("plugins.cfg", "ogre.cfg", "Ogre.log");
    delete root;
    return 0;
}

Right click on the solution, specify the include paths to the headers you used in your program.
In configuration properties> general> character set, specify it as "Use Multi-Byte Character Set". This prevents errors due to an old wchar typedef.
Specify additional library directories for the linker when necessary. To Linker> Input, add "OgreMain_d.lib;OIS_d.lib" for Ogre and if using OpenGL, add "opengl32.lib;glu32.lib"
If any other problems, check if your working directory is the same as your output directory.
That's it! Your program should build and compile.

Some errors you may encounter when running your program: If OgreMain_d.dll isn't found, simply find it in the Ogre soure directory, and paste it into your project's Debug directory. You may have to copy many other resource files of Ogre into your project's Debug directory (depending on which of those files are required for your program) for portability reasons.

For viewing the paths of variables like $(TargetPath) etc, just click the combobox that shows up when you click on any of the property values, and a small dialog box will open up. Click and Click "Macros >>" to see the values/paths.

It helps to set the OGRE_HOME Windows environment variable. Right-click on "My Computer", click properties > Advanced > Environment variables > System Variables > New.
Create a new environment variable named OGRE_HOME and give it a value which is the path to your Ogre source folder ogre_src_v1-7-3. You can use this variable in VS whenever you're specifying paths. You can use it like $(OGRE_HOME).

Please add more info to this file if you have done something more or encountered errors and found a solution to it.

My colleagues helped a lot during this build. More help I got from here: http://blog.tidalware.com/2009/08/building-ogre-with-visual-studio/
and here: http://blog.tidalware.com/2009/06/ogre-and-visual-studio-beginners-faq/
and on the official Ogre website. You'll also get a lot of help with a Google search. Especially when you run into build errors.

All the best brave developer! :-)

like image 179
Nav Avatar answered Sep 27 '22 21:09

Nav