天天看點

Ogre源碼在VS2005(VC8)中的配置方式

Ogre源碼在VS2005(VC8)中的配置方式

(參照 Ogre源碼在VS2008(VC9)中的配置方式 此文所寫,其實配置方式都差不多,就是有些小的地方有些許不同而已。

位址:http://blog.csdn.net/zeroboundary/archive/2008/11/30/3414086.aspx)

呃,今天終于開始Ogre之旅了。

不過配置還是花了不少的時間才搞定,就是需要些耐心。

準備工作:

首先安裝

1.         Microsoft Visual Studio 2005(此處使用的VS2005中文版)(開發工具,不用介紹了)注意這裡必須要安裝#sp1,官方網站特别強調,否則會出現未知的錯誤。不過大家一般使用vs2005的都會安裝sp1更新檔的哈。

2.         DXSDK_Aug09最新 (此處我安裝在D:\Program Files\Microsoft DirectX SDK (August 2009)目錄下) (完全安裝大約需要1G空間)

3.         ×××位址http://www.ogre3d.org/download/source

OGRE 1.6.4 Source For Windows 27 September 2009 49.5Mb
Visual C++.Net 2005 (8.0) SP1 Precompiled Dependencies 28 December 2007 15.7Mb Please note – you must have installedVS2005 Service Pack 1. You may also be interested in the debug symbols.

參考官網上的教程:http://www.ogre3d.org/wiki/index.php/Building_From_Source#Visual_C.2B.2B_2005_.28VC8.2FSP1.29

正确操作步驟:

1.         解壓 ogre-v1-6-4.zip(源碼包)(請確定磁盤空間足夠:正确編譯後的檔案總和大約是3.3G。好大哦)

2.         解壓 OgreDependencies_VC8SP1_Eihort_20071227.zip

3.         将 OgreDependencies_VC8SP1_Eihort_20071227.zip解壓後的兩個檔案夾Samples和Dependencies拷貝到 ogre目錄(ogre-v1-6-4.zip(源碼包)解壓後的目錄)下,如果提示檔案或目錄已存在,則直接覆寫. 注意這個非常重要,但是很容易被忽略,我就是這樣。否則編譯不通過的,因為這個裡面有ogre需要連結的第三方庫。要注意的是,ogre3D.cn貌似好久都沒更新了,是以建議上ogre3D.org,也就是官網非中文網.cn尋求解決方法。

4.         輕按兩下Ogre目錄下的Ogre_vc8.sln檔案,即:打開Ogre源碼解決方案

這裡遺忘了一個步驟:

4.5.         打開 Ogre_vc9解決方案下的工程的屬性頁

a.         将工程屬性頁中的    配置屬性 -> C/C++     ->    正常       ->    附加包含目錄 添加:Microsoft DirectX SDK (August 2008)目錄下的Include目錄(Microsoft DirectX SDK (August 2008)為剛剛安裝的Direct3Dsdk預設目錄)

b.         将工程屬性頁中的    配置屬性 -> 連接配接器    ->    正常       ->    附加庫目錄 添加:Microsoft DirectX SDK (August 2008)\Lib 目錄下的x86目錄(32位機 x64為64位機)

5.         編譯整個解決方案。

6.         經過30分鐘編譯,整個解決方案編譯成功

《========== 生成: 成功50 個,失敗0 個,最新0 個,跳過0 個==========》

7.       測試下,啟動ogremain執行個體,彈出個對話框。看看其他的執行個體,基本ok。但是有兩三個示例貌似是有問題的。哇,可愛的食人魔。

Ogre源碼在VS2005(VC8)中的配置方式

         但是貌似vs2008的還需要改些東東才能成功啟動執行個體。vs2008可以參考: http://blog.csdn.net/zeroboundary/archive/2008/11/30/3414086.aspx)

以上就是我在vs2005下關于Ogre源碼的配置方式。

接下來就是要建立第一個Ogre程式了。這個就沒上面的那麼順利了,要麻煩些。

參考官網教程SettingUpAnApplication:

http://www.ogre3d.org/wiki/index.php/SettingUpAnApplication#Microsoft_Visual_C.2B.2B_.NET

其實可以簡單點用:Also see The Complete Blanks Guide To Using The OGRE SDK AppWizard. 這個可以這樣,但是是需建立在ogre3D SDK的。

忽略,選擇手動建立Ogre程式:

1.建立一個普通'Win32空項目,建立一個新項 'Project -> Add New Item...'. 為main.cpp,從普通教程中copy個最簡單的代碼過來,儲存,ok。

看網站教程:

To clarify where the DLL files should be, an easy way is to copy the \bin folder (containing \debug and \release) and the \media folder from the OGRE installation directory to your Testproject folder (note: in this case you might be copying DLLs that won't be needed, but it's the hassle-free way). If you follow the convention presented above and you created folders for the header, scripts and source files, you have the following folders under \Testproject (excluding subfolders): 'bin', 'include', 'media', 'testsolution', 'scripts', and 'src'. However, if you don't want to copy them while running your Testproject from Visual Studio just add the path to OGRE's DLL files to the %PATH% global environment variable like this:

Debugging : Environment                             = PATH=%PATH%;%OGRE_HOME%\bin\debug

and for the release version

Debugging : Environment                             = PATH=%PATH%;%OGRE_HOME%\bin\release

This will not modify the %PATH% environment variable permanently, just for the given run, so its safer. You could modify it globally for all windows applications like this:

My Computer -> Properties -> Advanced -> Environment Variables -> System Variables -> Path    += ;%OGRE_HOME%\bin\debug      

or

My Computer -> Properties -> Advanced -> Environment Variables -> System Variables -> Path      
呃,這段後面沒怎麼看懂,是以不能偷懶了,隻能乖乖地最簡單的實作,把上面說的那些目錄copy到我剛建立的新項目目錄下。暫時隻能這麼用,誰叫自己這麼菜。      
配置項目屬性:      
Debugging : Command                                 = $(OutDir)\$(ProjectName).exe
Debugging : Working Directory                       = $(OutDir)
C/C++ : Preprocessor : Preprocessor Definitions += _STLP_DEBUG (only in Debug mode, not needed for .Net 2003 and 2005)
C/C++ : Code Generation : Use runtime library   = Multithreaded Debug DLL (Multithreaded DLL in Release)
Linker : General : Output File                            = ..\bin\Debug\[appname].exe
Linker : Input : Additional Dependencies                += OgreMain_d.lib OIS_d.lib  (OgreMain.lib OIS.lib in Release)      

對應我的項目屬性配置

Debugging : Command                                 = $(OutDir)\$(ProjectName).exe

Debugging : Working Directory                       = $(OutDir)

這兩個都一樣。

C/C++ : Preprocessor : Preprocessor Definitions += _STLP_DEBUG (only in Debug mode, not needed for .Net 2003 and 2005)

這個忽略掉note:only in Debug mode, not needed for .Net 2003 and 2005

Linker : General : Output File                            = $(OutDir)\$(ProjectName).exe 一般項目生成後預設就可以

Linker : Input : Additional Dependencies                += OgreMain_d.lib OIS_d.lib (OgreMain.lib OIS.lib in Release)

這個也一樣。

C/C++ : General : Additional Include Directories   = ..\include;$(OGRE_SRC)\OgreMain\include;$(OGRE_SRC)\Samples\Common\Include
Linker : General : Additional Library Directories         = $(OGRE_SRC)\OgreMain\Lib\Debug      
呃,這裡 $(OGRE_SRC) 這個環境變量不知道怎麼弄呃,安裝了SDK後預設環境變量中就有OGRE_HOME,這個就是OGRE的預設安裝目錄。      
但是源碼是zip格式的,解壓出來的,是以沒有自動生成環境變量$(OGRE_SRC) ,在網站上找了找也沒找到這個怎麼生成的,是以自己就直接在環境變量下按照OGRE_HOME寫一個OGRE_SRC的環境變量,      
結果是運作後說找不到***.lib ***.h 等。失敗,又不能偷懶了,都怪自己太菜,哎,隻能寫絕對路徑了:      
希望某位高手看到後能夠指點下,感激不敬。。。。      
C/C++ : General : Additional Include Directories   =..\include; d:\Project\ogre-v1-6-4\ogre\OgreMain\include; d:\Project\ogre-v1-6-4\ogre\Samples\Common\Include; D:\Project\ogre-v1-6-4\ogre\Dependencies\include      
Linker : General : Additional Library Directories         =d:\Project\ogre-v1-6-4\ogre\lib;d:\Project\ogre-v1-6-4\ogre\Dependencies\lib\Debug      
發現網站上提示的目錄并不是完全準确的,是以就得自己調了,缺少哪個庫後在source裡面找到庫檔案,然後把庫的路徑包含進去。      
最後編譯通過,運作,提示ogremain.dll找不到,郁悶,dll我都全部copy過來了啊,怎麼會找不到呢??暈,解決方案下有兩個debug目錄,放錯目錄了。      
ok,将dll啊什麼的再又copy一份過去,繼續。結果出現media目錄下的*.zip檔案打不開,呃目錄層級有問題,放到正确的層級目錄下,調試      
哇,出現了可愛食人魔頭像,高興。done。      
回頭想想,不知道是不是我太菜了,弄得這麼複雜一個啊。但是按照網站上的步驟其實差不多啊,就是每次都要copy 所有debug目錄下的dll和media目錄到新的工程目錄下,真是麻煩,但是這也沒辦法啊,我也想偷懶啊。      
期待高手的幫忙。      
不行,想偷懶的話,還是有點方法的,就是将所有生成的exe生成目錄指向sample\common\bin\debug,像Ogre提供的示例一樣,都放在這個目錄下,不就不要copy這些個麻煩東東過去了嘛。哈哈,begin:      
模仿Ogre_VC8.sln中的單個工程項目屬性中的生成目錄、包含路徑、包含庫。      
記錄下自己的工程屬性修改後的:      
輸出目錄:D:\Project\ogre-v1-6-4\ogre\Samples\Common\bin\$(ConfigurationName)      
中間目錄:D:\Project\ogre-v1-6-4\ogre\Samples\Common\obj\$(ConfigurationName)      
指令:D:\Project\ogre-v1-6-4\ogre\Samples\Common\bin\$(ConfigurationName)\$(TargetFileName)      
工作目錄:D:\Project\ogre-v1-6-4\ogre\Samples\Common\bin\$(ConfigurationName)      
c++\正常\附加包含目錄:D:\Project\ogre-v1-6-4\ogre\Samples\Common\include; d:\Project\ogre-v1-6-4\ogre\OgreMain\include; d:\Project\ogre-v1-6-4\ogre\Samples\Common\Include; D:\Project\ogre-v1-6-4\ogre\Dependencies\include       
連接配接器\正常\附加庫目錄:d:\Project\ogre-v1-6-4\ogre\lib;d:\Project\ogre-v1-6-4\ogre\Dependencies\lib\Debug      
呃 用的都是絕對路徑,是以這個環境變量OGRE_SCR真的很重要。      
ok,好了,編譯,連結,運作,可愛的ogre頭像出現了,然後在D:\Project\ogre-v1-6-4\ogre\Samples\Common\bin\Debug 目錄下可以找到這個啟動程式exe。      
然後就可以一邊欣賞ogre源碼,一邊調試着自己寫的代碼了。開心狀。。。      

繼續閱讀