1. 程式人生 > >從原始碼編譯OSG

從原始碼編譯OSG

Windows 下:

2。使用CMake工具編譯OSG。

    1)把CMakeLists.txt 拖放到CMake軟體的GUI介面上,可以選擇更改安裝路徑:"Where to build the binaries"。該路徑是OSG的初始編譯路徑。

    2)點選 'Configure' ,之後出現的紅色內容是告訴你這些內容將可以由你指定,並在後面的generate中據此生成,如E:/temp。

如果出現以下錯誤:

Looking for include files CMAKE_HAVE_PTHREAD_H

Looking for include files CMAKE_HAVE_PTHREAD_H - not found.

Found Threads: TRUE

Could NOT find LibXml2 (missing: LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)

Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)

Could NOT find OpenAL (missing: OPENAL_LIBRARY OPENAL_INCLUDE_DIR)

Could NOT find JPEG (missing: JPEG_LIBRARY JPEG_INCLUDE_DIR)

Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR)

Could NOT find TIFF (missing: TIFF_LIBRARY TIFF_INCLUDE_DIR)

Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS

Performing Test _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS - Failed

Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS

Performing Test _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS - Failed

Performing Test _OPENTHREADS_ATOMIC_USE_SUN

Performing Test _OPENTHREADS_ATOMIC_USE_SUN - Failed

Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED

Performing Test _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED - Success

Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC

Performing Test _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC - Failed

將之解壓縮並複製到OSG原始碼目錄“OpenSceneGraph-2.8.3”下,並將之命名為3rdParty,當然也可以不重新命名,直接在CMake過程中指定:ACTUAL_3DPARTY_DIR.

當然,這一步不是必要的,只要'Generate'按鈕可以使用即可。但最好還是這麼做,可以支援更多型別的資料嘛(你應該已經看到了3dParty中有GDAL等內容)。

還要注意,在configure過程中,也最好啟用BUILD_OSG_EXAMPLES;

另外,CMAKE_INSTALL_PREFIX 路徑要指定為應用程式使用時的路徑,該路徑就是run-time路徑,即最終從編譯檔案copy到的檔案路徑,最好不和:"Where to build the binaries"指定的路徑一致,如E:/runtime/OSG_runtime。

3。在安裝的路徑下找到OpenSceneGraph.sln,開啟,編譯之。

  。。。。。。。。。真無語,要編譯n久。。> one hour

4。繼續在該OpenSceneGraph.sln工程中找到INSTALL,右擊->生成(編譯)。把該copy的copy到CMAKE_INSTALL_PREFIX指定的路徑下。

5。 新增環境變數

1)OSG_ROOT 指向上述CMAKE_INSTALL_PREFIX指定的路徑

OSG_BIN_PATH = %OSG_ROOT%/bin
OSG_INCLUDE_PATH = %OSG_ROOT%/include
OSG_LIB_PATH = %OSG_ROOT%/lib
OSG_SAMPLES_PATH = %OSG_ROOT%/share/OpenSceneGraph/bin
OSG_FILE_PATH = xxx/OpenSceneGraph-Data-X.X(這裡的路徑是下載解壓縮後的Sample Dataset所在位置,後面的X.X指該OpenSenceGraph-Data的版本號,我是把這個資料夾也放到OSG_ROOT下的,所以我的是E:/runtime/OSG_runtime/OpenSceneGraph-Data-2.8.0)

2)在path中新增%OSG_BIN_PATH% 和 %OSG_SAMPLES_PATH%的路徑

6。 測試下安裝是否成功

cd 到CMAKE_INSTALL_PREFIX指定的安裝路徑下,輸入相關osgversiond,osglogod等。注意此時所有的命令執行程式、DLL、LIB檔案都有一個'd'的字尾,那是因為我在編譯工程的時候用的是Debug版本。

7。 具體的,可以參照下述的參考文獻。

參考文獻: