如何使用 Visual Studio 在 Windows 上构建 OGRE?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7776642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:16:45  来源:igfitidea点击:

How to build OGRE on Windows using Visual Studio?

windowsvisual-c++buildogre3dogre

提问by Nav

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.

希望这能帮助很多在 Windows 上安装 OGRE 的人。我做到了,我不希望其他任何人遭受同样程度的折磨。

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.

我试图通过解释比其他网站上解释的更多的步骤和细节来使这种解释有所不同。其他人根本想不到记录的问题和解决方案。

回答by Nav

The normal way to build Ogre from source:

从源代码构建 Ogre 的正常方法:

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.

获取一个新的 Ogre 自解压器(这些说明适用于 Ogre 1.7.3 版)
下载并安装 CMake
下载并安装 DirectX SDK
在至少有 4.3GB 空间的驱动器中创建一个名为“OGRE”的文件夹。
将 ogre 源文件解压到 OGRE 文件夹中。下载 Ogre 依赖项并将它们解压到 OGRE 文件夹中。运行 CMake 并选择 Visual Studio 10 作为默认编译器。
指定 Ogre 的源目录。这是 ogre_src_v1-7-3 文件夹。还要将windows中的OGRE_HOME环境变量设置为ogre_src_v1-7-3的完整路径。(通过右键单击我的计算机、属性、高级、环境变量、用户变量、新建来设置它)为 CMake 指定一个目录来放置它创建的二进制文件。您可以在 OGRE 文件夹中创建一个名为“Binaries”的目录。
在 CMake 中按“配置”。
它会显示很多红线条目。对于 OGRE_DEPENDENCIES_DIR 条目,指定您在上面提取的依赖项文件夹的路径。
再次单击“配置”,所有这些红线将变为白色,这意味着配置工作正常。
点击“生成”。
CMake 就是这样。
转到二进制文件夹,您将看到 OGRE.sln。双击它在 VS2010 中打开它。
要么右键单击“ALL-BUILD”项目并构建或按F5(如果按F5,那么当构建完成时,它会说它无法运行,这没关系,因为所有构建并不意味着运行)
在具有 1GB RAM 的双核 2GHz PC 上,构建过程大约需要 30 分钟。
将“示例浏览器”项目设置为活动项目,然后按 F5 运行它。
就是这样!Ogre 已在您的系统上配置。

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

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

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.

为避免出现很多问题,请确保您从互联网上以原始文件夹/zip 文件/自解压器的形式获取 Ogre 源代码,并在您的机器上安装 DirectX SDK。在你的系统上为 Ogre 创建一个文件夹并将源代码文件夹存储在那里。完成后,Ogre 源代码、二进制文件和构建文件将总共占用大约 4.3GB 的磁盘空间。

[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)]

[注意:不要在您的系统上安装 Visual Studio 2008。如果您这样做了,并且在构建 ogre.sln 时导致问题(致命错误 C1902:程序数据库管理器不匹配;请检查您的安装),如果您使用 VS2010 构建,只需删除 mspdb100.dll 文件。(目前还没有确认问题是否真的是因为安装了VS2008。可能是因为这个文件中写了一个步骤,其中mspdb100.dll被复制到了一个不应该存在的文件夹中。以防万一你用VS2008重新构建Ogre,显示“致命错误”,然后删除mspdb80.dll是解决方案)]

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

将 Ogre 源文件解压缩到系统中的文件夹中。很高兴有这样一个目录路径:
“你的根\食人魔\二进制\”的二进制文件

*“你的根\食人魔\ ogre_src_v1-7-3 \” *为源

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.

CMake:
下载并安装 CMake,它有助于配置 Ogre 以安装到您的系统中。
运行 CMake 可执行文件。
选择“将 cmake 添加到当前用户的系统路径”。
找到安装cmake的地方,然后运行\CMake 2.8\bin\cmake-gui.exe
指定二进制文件和源代码的目录。
单击 CMake GUI 上的“高级”复选框
将 CMAKE_CXX_COMPILER 设置为 your-Visual-Studio-installation-path/VC/bin/cl.exe
将 CMAKE_C_COMPILER 设置为 your-Visual-Studio-installation-path/VC/bin/cl.exe
将 CMAKE_RC_COMPILER 设置为 what-path-your-RC.exe-file-is-in/RC.Exe(在“程序文件”文件夹中搜索,您可能会找到 rc.exe)
单击“配置”,它可能会出现找不到 mspdb100.dll 的错误
从 your-Visual-Studio-installation-path\Common7\IDE 复制 mspdb100.dll 并将其粘贴到 your-Visual-Studio-installation-path \VC\bin(不是正确的方法,但很好...;如果在 Ogre 的构建过程中,出现类似“程序数据库管理器不匹配”的错误,您稍后可能必须删除该文件)
一旦配置完成后,单击“生成”,这将生成 ogre.sln 文件或“.dsw”文件,当您单击该文件时,您的 ogre.sln 文件将被创建。更多信息请见下文。
笔记:Cmake 维护一个缓存。要随时重新配置 cmake,您必须清除缓存。Cmake 2.8 在菜单中有清除缓存的选项。如果您安装 cmake 2.6.4,您将能够使用窗口底部的按钮清除缓存。清除缓存后,您就可以选择编译器。我选择了 VS2006 并且没有更改本机编译器的任何选项。只是保持原样。
注2:当我安装Visual C++ 2006 时,C 和C++ 编译器现在可以编译cmake 的测试文件,但是cmake 找不到位于ogre_src_v1-7-3 的bin 文件夹中的某个dll。它在 \tpcsed.com\projectshare\mapex\OGRE3D 文件夹中查找,所以我将 bin 文件夹复制到 \tpcsed.com\projectshare\mapex\OGRE3D 文件夹中。那时一切正常。

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.

如果您的 Visual Studio 版本无法实现上述配置,您可能必须安装 VS2006 才能指定正确的 c1.exe 和 rc.exe 文件。VS2010 的 c1.exe 和 rc.exe 对我不起作用。

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)

编译任何依赖项:
解压 OgreDependencies_MSVC_20101231.zip Goto your-root\Ogre\ogre_src_v1-7-3\Dependencies\src 使用 VS2010 打开 OgreDependencies.VS2010.sln(或对应于你的 VS 的 sln 文件)右键单击解决方案并构建调试和发布的解决方案(右键单击解决方案>属性>配置>配置管理器按钮>活动解决方案配置组合框)

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.

构建 Ogre:
单击 your-root\Ogre\ogre_src_v1-7-3\bin\ogre.dsw 文件并确保它在您使用的 VS 版本中打开。就我而言,它是 VS2010(如果您在 CMake 中使用了 VS2006,您将拥有一个 dsw 文件,它将解决方案转换为您的 VS 版本)
将创建一个 ogre.sln 文件。双击它。
右键单击 ALL_BUILD 项目,然后单击构建。你应该为 Release 和 Debug 做这件事,但为调试做这件事对我来说已经足够了(暂时)。
右键单击 INSTALL 项目并单击 Build。你应该为 Release 和 Debug 做这件事,但为调试做这件事对我来说已经足够了(暂时)。
要么执行上述 2 个步骤,要么只需单击清理并构建整个解决方案。
如果发现错误,请搜索构建失败的项目,阅读错误并更正。所有项目至少必须成功构建才能进行调试。

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!

如果构建失败,则清理项目并重新构建。或者从 cmake 步骤重新开始。
如果存在构建错误,请通过查看列出的错误找出发生错误的原因。这可能是因为你没有在你的系统上安装 DirectX SDK 或者因为你在 ogre.sln 项目属性中指定了错误的路径。检查所有值以查看所有路径是否正确。
就是这样!

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

可选的依赖项,如 TBB、Boost 等。我没有尝试安装。食人魔没有它也能工作。

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

运行:
尝试一个小的 Og​​re 应用程序。您应该能够运行的最简单的方法是:

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

右键单击解决方案,指定您在程序中使用的头文件的包含路径。
在配置属性>常规>字符集,将其指定为“使用多字节字符集”。这可以防止由于旧的 wchar typedef 导致的错误。
必要时为链接器指定其他库目录。到Linker> Input,为Ogre添加“OgreMain_d.lib;OIS_d.lib”,如果使用OpenGL,添加“opengl32.lib;glu32.lib”
如果有其他问题,请检查您的工作目录是否与您的输出目录相同。
就是这样!您的程序应该构建和编译。

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.

运行程序时可能会遇到的一些错误: 如果找不到 OgreMain_d.dll,只需在 Ogre soure 目录中找到它,然后将其粘贴到项目的 Debug 目录中即可。出于可移植性的原因,您可能需要将 Ogre 的许多其他资源文件复制到您项目的 Debug 目录中(取决于您的程序需要哪些文件)。

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.

要查看诸如$(TargetPath)等变量的路径,只需单击当您单击任何属性值时显示的组合框,就会打开一个小对话框。单击并单击“宏>>”以查看值/路径。

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

它有助于设置 OGRE_HOME Windows 环境变量。右键单击“我的电脑”,单击属性 > 高级 > 环境变量 > 系统变量 > 新建。
创建一个名为 OGRE_HOME 的新环境变量,并为其指定一个值,该值是 Ogre 源文件夹 ogre_src_v1-7-3 的路径。每当您指定路径时,您都可以在 VS 中使用此变量。你可以像$(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.

我的同事在这个构建过程中提供了很多帮助。我从这里得到的更多帮助:http: //blog.tidalware.com/2009/08/building-ogre-with-visual-studio/
和这里:http: //blog.tidalware.com/2009/06/ogre- and-visual-studio-beginners-faq/
和 Ogre 官方网站。您还可以通过 Google 搜索获得很多帮助。尤其是当您遇到构建错误时。

All the best brave developer! :-)

所有最勇敢的开发者!:-)