虽然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%
然后在命令中运行: