前言
由于工程原因, 学习一下Ogre面向对象图形渲染开源引擎, 慢慢爬坑吧。首先还是环境的配置问题哎. 其实最重要的是要预先编译三方库, 虽然官方说可以自动编译, 但是在自己电脑上还是出现了无法解析外部符号之类的问题, 正常情况下我就认为是三方库的lib出现了问题, 最后额外编译三方库才得到了解决, 话不多说, 安装开始.
环境: windows10、VS2013、Ogre1.10
所需code:
官方网址: Ogre1.10(github)、三方库 、SDL2 、boost
【注】boost最好下载电脑所对应的VS版本, 我的电脑是VS2013, 所以下载boost_1_61_0-msvc-12.0-64.exe
百度网盘:
Ogre: 链接: https://pan.baidu.com/s/1TIPy-rndd-uBZJZynkvzrw 密码: uf5c
三方库: 链接:http://pan.baidu.com/s/1c1XCh0W 密码:db29
SDL2: 链接:http://pan.baidu.com/s/1qXAnaA4 密码:hegq
BOOST: 链接:http://pan.baidu.com/s/1pLMG7px 密码:q8a8
国际惯例, 参考博客:
OGRE 2.1 Windows 编译
官方manual
安装
三方库配置
先安装boost, 一直下一步就行了, 我安装的位置是
D:\Package\boost_1_61_0
, 注意设置一下环境变量
再看看我安装后的目录有哪些文件新建一个文件夹
Ogre1.10
放置三方库以及后续的编译好的程序, 将三方库解压进来, 并在D:\Package\Ogre1.10\cabalistic-ogredeps-a337c4874a15\src
新建文件夹SDL2
, 将下载的SDL2
压缩包中的大约40个文件复制丢进来, 并在D:\Package\Ogre1.10\cabalistic-ogredeps-a337c4874a15
新建一个build
文件夹, 接下来打开cmake-GUI
, 设置好相关路径
直接点击
Configure
, 截图一下我的结果
调试日志如下:The C compiler identification is MSVC 18.0.40629.0 The CXX compiler identification is MSVC 18.0.40629.0 Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe -- works Detecting C compiler ABI info Detecting C compiler ABI info - done Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe -- works Detecting CXX compiler ABI info Detecting CXX compiler ABI info - done Detecting CXX compile features Detecting CXX compile features - done Looking for DirectX... DirectX_PREFIX_PATH changed. Check size of void* Check size of void* - done Found DirectX: C:/Program Files (x86)/Windows Kits/8.1/Lib/winv6.3/um/x86/d3d9.lib DX lib dir: C:/Program Files (x86)/Windows Kits/8.1/Lib/winv6.3/um/x86 DX lib dir: C:/Program Files (x86)/Windows Kits/8.1/Lib/winv6.3/um/x86 Check size of void* Check size of void* - done Configuring done
虽然全是红色的, 但是再
Configure
一下就没了, 如果还有红色的, 那你就得好好核对一下我上面贴的一堆图了. 随后Generate
一下, 就看到build
文件夹下已经有完整的VS工程啦
然后打开
OGREDEPS.sln
, 对ALL_BUILD
生成一次, 就发生问题了错误 944 error MSB6006: “cmd.exe”已退出,代码为 1。 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets 170 5 SDL2
这时候就考察VS的调试功底了, 直接去输出窗口看具体位置:
5> Move SDL2 install files into the Release and Debug folders. 5> CMake Error at D:/Package/Ogre1.10/cabalistic-ogredeps-a337c4874a15/build/src/SDL2-prefix/src/SDL2-stamp/SDL2-MoveInstallFiles-Debug.cmake:16 (message): 5> Command failed: 1 5> 5> 'C:/Program Files/CMake/bin/cmake.exe' '-Dmake=' '-Dconfig=Debug' '-P' 'D:/Package/Ogre1.10/cabalistic-ogredeps-a337c4874a15/build/src/SDL2-prefix/src/SDL2-stamp/SDL2-MoveInstallFiles-Debug-impl.cmake' 5> 5> See also 5> 5> D:/Package/Ogre1.10/cabalistic-ogredeps-a337c4874a15/build/src/SDL2-prefix/src/SDL2-stamp/SDL2-MoveInstallFiles-*.log 5> 5> 5>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(170,5): error MSB6006: “cmd.exe”已退出,代码为 1。
很清晰地发现错误日志已经被丢到
SDL2-MoveInstallFiles-*.log
中, 去瞅一眼Error copying file "bin/SDL2.dll" to "bin/Debug/SDL2.dll". CMake Error at D:/Package/Ogre1.10/cabalistic-ogredeps-a337c4874a15/build/src/SDL2-prefix/src/SDL2-stamp/SDL2-MoveInstallFiles-Debug-impl.cmake:29 (message): Command failed (1):'C:/Program Files/CMake/bin/cmake.exe' '-E' 'copy' 'bin/SDL2.dll' 'bin/Debug/SDL2.dll'
很多人看到这类英文错误就直接问人, 小兄弟啊, 遇到错误先认真看一遍, 至少先翻译一下也行啊. 嗯, 闲话不多说, 这个问题就是复制
SDL2.dll
的时候出问题了, 三方库的输出目录是D:\Package\Ogre1.10\cabalistic-ogredeps-a337c4874a15\build\ogredeps
, 可以发现在bin
下的确有SDL2d.dll
躺着, 主要是由于我们编译的是Debug
模式. 所以没找到SDL2.dll
, 导致错误, 解决方法很简单, 切换Release
模式重新编译, 或者手动把这个文件拷贝进去.建议两个都做一遍, 反正不冲突.最后对
INSTALL
生成一遍,一定要核对一下相关文件(VS工程中出现的那几个三方库)是否在ogredeps
文件中, 主要有
include: 相关头文件, 这个一般都存在
lib: 相关lib库文件
bin: 相关dll库文件
如果不在, 直接针对每个项目右键打开文件资源管理器, 找到以后复制过来.
编译Ogre源程序
将
ogre-master
解压到D:\Package\Ogre1.10
中, 然后将刚才编译的三方库ogredeps
放入到ogre-master
中, 并更名为Dependencies
, 在D:\Package\Ogre1.10
下新建文件夹Ogre
用于存储编译的Ogre
, 在cmake-gui
中设置路径
然后Configure
, 调试信息太多了, 就不贴了, 第二次Configure
出现错误send_errorD:/Package/Ogre1.10/Ogre/Dependencies/bin/debug/cg.dll did not exist, can't install! send_errorD:/Package/Ogre1.10/Ogre/Dependencies/bin/release/cg.dll did not exist, can't install!
这个文件在刚才编译三方库的时候
D:\Package\Ogre1.10\cabalistic-ogredeps-a337c4874a15\build\bin
里面, 同时我们还发现另外两个dll:OIS.dll
和Remotery.dll
, 保险起见都复制过去吧,两种模式Debug
和Release
, 重新Configure
就没问题了, 调试日志如下
Configuring OGRE 1.10.10Search path: D:/Package/Ogre1.10/Ogre/Dependencies;D:/Package/Ogre1.10/ogre-master/Dependencies;D:/Package/Ogre1.10/Ogre/../Dependencies;D:/Package/Ogre1.10/ogre-master/../DependenciesLooking for ZZip...Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) Found ZZip: optimized;D:/Package/Ogre1.10/ogre-master/Dependencies/lib/Release/zziplib.lib;debug;D:/Package/Ogre1.10/ogre-master/Dependencies/lib/Debug/zziplib_d.libLooking for FreeImage...Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) Found FreeImage: optimized;D:/Package/Ogre1.10/ogre-master/Dependencies/lib/Release/FreeImage.lib;debug;D:/Package/Ogre1.10/ogre-master/Dependencies/lib/Debug/FreeImage_d.libLooking for FREETYPE...Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) CMAKE_PREFIX_PATH: D:/Package/Ogre1.10/Ogre/Dependencies;D:/Package/Ogre1.10/ogre-master/Dependencies;D:/Package/Ogre1.10/Ogre/../Dependencies;D:/Package/Ogre1.10/ogre-master/../DependenciesCMAKE_PREFIX_PATH: D:/Package/Ogre1.10/Ogre/Dependencies;D:/Package/Ogre1.10/ogre-master/Dependencies;D:/Package/Ogre1.10/Ogre/../Dependencies;D:/Package/Ogre1.10/ogre-master/../DependenciesFound FREETYPE: optimized;D:/Package/Ogre1.10/Ogre/Dependencies/lib/freetype.lib;debug;D:/Package/Ogre1.10/ogre-master/Dependencies/lib/Debug/freetype_d.libLooking for DirectX9...Found DirectX9: D:/Package/Microsoft DirectX SDK (June 2010)/Lib/x86/d3d9.libLooking for DirectX11...Found DirectX11: d3d11.lib;dxgi.lib;dxguid.libLooking for Cg...Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) Found Cg: D:/Package/Ogre1.10/ogre-master/Dependencies/lib/Release/cg.libLooking for POCO...Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) Could not locate POCOLooking for TBB...Could not locate TBBLooking for GLSL_Optimizer...Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) Could not locate GLSL_OptimizerLooking for HLSL2GLSL...Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) Could not locate HLSL2GLSLCould NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) Looking for Softimage...Could not locate Softimage------------------------------------------------------------------------------- The following external packages were located on your system.-- This installation will have the extra features provided by these packages.+ zlib+ zziplib+ freeimage+ freetype+ OpenGL+ OpenGL 3++ OpenGL ES 1.x+ OpenGL ES 2.x+ OpenGL ES 3.x+ DirectX9+ DirectX11+ cg+ Python+ SDL2------------------------------------------------------------------------------- The following OPTIONAL packages could NOT be located on your system.-- Consider installing them to enable more features from this software.+ boost: Boost (general) <http://boost.org>+ boost-thread: Used for threading support <http://boost.org>+ POCO: POCO framework <http://pocoproject.org/>+ tbb: Threading Building Blocks <http://www.threadingbuildingblocks.org/>+ GLSL Optimizer: GLSL Optimizer <http://github.com/aras-p/glsl-optimizer/>+ HLSL2GLSL: HLSL2GLSL <http://hlsl2glslfork.googlecode.com/>+ OpenEXR: Load High dynamic range images <http://www.openexr.com/>+ Doxygen: Tool for building API documentation <http://doxygen.org>+ Softimage: Softimage SDK needed for building XSIExporter <FALSE>-----------------------------------------------------------------------------Could NOT find SWIG (missing: SWIG_EXECUTABLE SWIG_DIR) Could NOT find SWIG (missing: SWIG_EXECUTABLE SWIG_DIR) ----------------------------------------------------------------------------FEATURE SUMMARY----------------------------------------------------------------------------Building components:+ Bites [BETA]+ HLMS [BETA]+ MeshLodGenerator+ Overlay+ Paging+ Property [DEPRECATED]+ Python [BETA]+ Java/ JNI [BETA]+ RTShader System+ RTShader System Core Shaders+ RTShader System Extensions Shaders+ Terrain+ VolumeBuilding plugins:+ BSP scene manager+ Cg program manager+ Octree scene manager+ Portal connected zone scene manager+ Particle FXBuilding rendersystems:+ Direct3D 9+ Direct3D 11+ OpenGL+ OpenGL 3+Building executables:+ Samples+ ToolsBuilding core features:+ Mesh Lod+ DDS image codec (.dds)+ ETC image codec (.pkm, .ktx) + FreeImage codec (generic)+ ZIP archivesBuild type: sharedUse C++11 std library: OFFStore child nodes as: map [DEPRECATED]Thread safety: noneResourceManager behaviour: legacy [DEPRECATED]Use double precision: disabledNodes inherit transform: disabledAssert mode: release exceptionsAllocator type: standardSTL containers use allocator: disabledStrings use allocator: disabledMemory tracker (debug): disabledMemory tracker (release): disabled----------------------------------------------------------------------------Configuring doneGenerating done
Generate
一下, 生成VS2013的工程文件, 可以在D:\Package\Ogre1.10\Ogre
中找到.
【注】上述过程也可以在Cmake-GUI中不勾选OGRE_BUILD_DEPENDENCIES
,并且设置OGRE_DEPENDENCIES_DIR
为你的三方库目录, 好像更快一些
- 编译OGRE.sln
, 先ALL_BUILD
一下, 时间挺久的, 要盯着错误列表, 一旦出现错误, 就直接取消生成解决错误吧. 个人觉得很多人会出现外部符号无法解析问题, 一定是由于lib文件没折腾好引起的. 重新仔细核对上述步骤, 尤其是核对dll和lib是否折腾对.
【注】这里贴一下我编译好的三方库,便于大家核对 :链接:http://pan.baidu.com/s/1boDvokv 密码:lkap
然后就可以INSTALL
啦, 这个就是生成我们后续开发需要引用的Ogre
各种文件, 存在于D:\Package\Ogre1.10\Ogre\sdk
目录下, 以后开发就只需要它应该就可以了.
- 最后可以通过VS运行程序, 也可以通过
D:\Package\Ogre1.10\Ogre\bin\debug\SampleBrowser_d.exe
运行程序