雖然windows下也能用gcc編譯,這裏選擇visual studio(版本默認爲2012)
4.x版本的Opendtect的編譯可以參考:
http://blog.csdn.net/saga1979/article/details/5960334
5.x版本的Opendtect使用CMake來組織編譯,官方介紹可參考:
http://opendtect.org/rel/doc/Programmer/windows.html
只是官方文檔上提到的Qt、OpenSceneGraph外,沒說osggeo,其實這個包雖然在opendtect中,編譯時需要單獨對待
源代碼下載:
https://github.com/OpendTect
1、源文件準備
Qt:
推薦下載4.8.x版本。如果下載Qt的源代碼包自行編譯,而且使用vs2012以及以上版本,編譯4.8.x的QT,會出錯。
.\wtf/HashSet.h(180) : error C2664: 'std::pair<_Ty1,_Ty2>::pair(const std::pair<
_Ty1,_Ty2> &)' : cannot convert parameter 1 from 'std::pair<_Ty1,_Ty2>' to 'cons
t std::pair<_Ty1,_Ty2> &'
................
c:\users\heinz\qt\4.8.5\src\3rdparty\webkit\source\javascriptcore\heap\M
arkStack.h(195) : see reference to class template instantiation 'WTF::HashSet<Va
lueArg>' being compiled
with
[
ValueArg=void *
]
Generating Code...
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0
\VC\BIN\cl.EXE"' : return code '0x2'
Stop.
請參考下面的鏈接解決:https://qt.gitorious.org/qt/qt/commit/1bed55097b22f2071af71ebefc9897816977fd14
如果使用Qt5.x版本,直接使用cmake配置,會出現如下錯誤:
CMake Error at CMakeModules/ODQtUtils.cmake:23 (MESSAGE):
QTDIR not set
Call Stack (most recent call first):
CMakeModules/ODMacroUtils.cmake:96 (OD_SETUP_QT)
src/Basic/CMakeLists.txt:118 (OD_INIT_MODULE)
可以通過修改OpendTect-odxxx\CMakeModules\ODQtUtils.cmake:27解決:
#Try to find Qt5
list ( APPEND CMAKE_PREFIX_PATH ${QTDIR} )
find_package( Qt5Core QUIET NO_DEFAULT_PATH )
if ( Qt5Core_FOUND )
修改爲:
#Try to find Qt5
set( ENV{QTDIR} ${QTDIR} )
set ( QT_QMAKE_EXECUTABLE ${QTDIR}/bin/qmake${CMAKE_EXECUTABLE_SUFFIX} )
list ( APPEND CMAKE_PREFIX_PATH ${QTDIR} )
find_package(Qt5 REQUIRED Gui Core Sql Network )
if ( Qt5Core_FOUND )
通過查看https://github.com/OpendTect 中的該文件記錄,很早就存在支持qt5.x的配置,估計開發人員都使用4.x,對Qt5的測試基於某個人員的特定環境草草了事。
OpenSceneGraph:
官方的windows環境編譯文檔:http://www.openscenegraph.org/index.php/documentation/platform-specifics/windows/37-visual-studio
依賴包:http://www.openscenegraph.org/index.php/download-section/dependencies(如果使用不到可以不下載,我後來編譯opendtect沒有使用也順利啓動)
百度雲:http://pan.baidu.com/s/1o6KBwCi
在使用cmake配置的時候,記得加上/Zc:wchar_t-選項(使用vs2013編譯時,沒這麼做也順利通過)
osggeo:
可從這裏下載:https://code.google.com/p/osggeo/source/checkout
但需要修改一堆文件,我修改後上傳百度雲:http://pan.baidu.com/s/1eQCeoQu
opendtect:
需要配置QTDIR、osgGeo_DIR、OSG_DIR環境變量(在cmake-gui的界面中指定即可)
在編譯時,有兩個文件可能會導致編譯錯誤
\src\visBase\visscenecoltab.cc,如果使用的OpenSceneGraph版本大於3.3.1(目前最新爲3.3.3),會提示
1 IntelliSense: class "osgSim::ScalarBar::TextProperties" has no member "_font" e:\devlib\opendtect_svn\src\visBase\visscenecoltab.cc 84
#if OSG_MIN_VERSION_REQUIRED(3,3,1)//把這個數字改成大於使用的OpenSceneGraph就行了,比如(3,3,4),也可以找個低版本的OSG
# include <osgSim/ScalarBar>
# define mScalarBarType osgSim::ScalarBar
#else
# include <osgGeo/ScalarBar>
# define mScalarBarType osgGeo::ScalarBar
#endif
src/uiOSG/ui3dviewer.cc:
osg::NodeCallback* nodecb =view_->getSceneData()->getEventCallback();
修改爲:
osg::Callback* nodecb = view_->getSceneData()->getEventCallback();
或者:
osg::NodeCallback* nodecb = dynamic_cast<osg::NodeCallback*>(view_->getSceneData()->getEventCallback());
2、編譯
OSGGEO:
如果使用opendtect自帶的代碼,編譯時會出現一堆錯誤,大致可分爲兩類:
1、BoundingBox、BoundingSphere的類型混亂
osg::BoundingBox computeBound() const { return _boundingBox; }
protected:
osg::BoundingBox _boundingBox;
修改爲:
osg::BoundingSphere computeBound() const
{
_boundSphere.init();
_boundSphere.expandBy(_boundingBox);
return _boundSphere;
}
protected:
osg::BoundingBox _boundingBox;
mutable osg::BoundingSphere _boundSphere;
對於所有相關問題,都可以使用類似方法解決
2、osg::NodeCallback、osg::Callback相關
提供的修改方法供參考,首先在類聲明中:
//osg::ref_ptr<osg::NodeCallback> _cb;
osg::NodeCallback* _cb;
然後要在該類的構造函數中將成員初始化,參考如下:
ThumbWheel::ThumbWheel()
: _geode( new osg::Geode )
, _isTracking( false )
, _currentAngle( 0 )
, _hasFadeInOut( true )
, _animationStart( -1 )
, _animationTime( 1 )
, _mouseProximity( None )
, _rotationToDo( 0 )
, _rotationProgressToDo( 0 )
, _maxRotationProgress( 1 )
, _cb(0) //別忘了初始化指針
{
_geode->ref();
_geode->setCullingActive( false );
然後在對_cb賦值的地方使用dynamic_cast轉換指針,參考如下:
void ThumbWheel::removeRotateCallback( osg::NodeCallback* nc )
{
if ( nc==_cb )
_cb = dynamic_cast<osg::NodeCallback*>(_cb->getNestedCallback());//
else
_cb->removeNestedCallback( nc );
}
opendtect:
我使用vs2013遇到的錯誤有:
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __cdecl QString::toWCharArray(unsigned short *)const " (__imp_?toWCharArray@QString@@QEBAHPEAG@Z) referenced in function "public: unsigned short * __cdecl uiString::createWCharString(void)const " (?createWCharString@uiString@@QEBAPEAGXZ) D:\labs\opendtect\build\opendtect\src\Basic\uistring.obj Basic
解決方法如下:
如果不願意使用vs打開.sln文件編譯,可以使用命令行工具,格式爲:
msbuild xxx.sln /p:configuration=debug(或者release等其他有效配置)
編譯順序Qt->OSG->osggeo->opendtect
3、運行
如果採用32位編譯器編譯,在debug模式編譯結束後,\bin\win32\Debug目錄會有一堆文件:
如果不願意操作繁瑣的系統變量設置,可以寫個批處理文件將依賴庫的路徑加入,比如我的機器上是這樣:
set OSG_BIN=E:\devlib\build\osg_lib\3rdParty\bin;E:\devlib\build\osg\bin;E:\devlib\build\osggeo\Debug
set QT_BIN=E:\devlib\Qt\qt-everywhere-opensource-src-4.8.6\bin
set PATH=%OSG_BIN%;%QT_BIN%;%PATH%
然後在命令中運行: