osgEarth在Windows上的编译(V2015)

1. 环境

操作系统:win10

开发平台:vs2015

osgEarth版本:osgEarth2.10

2. 编译和安装

1.下载并解压

在d盘中新建osgEarth2.10文件夹将下载好的osgEarth2.10.zip解压到osgEarth2.10目录重命名为osgearth-2.10并新建osgEarth_build和osgEarth_install两个目录.目录结构如下:

d:
├─osgEarth2.10
    ├─osgEarth_build
    └─osgEarth_install
    └─osgearth-2.10
        └─源代码文件

2.在osgearth-2.10目录下新建third_party目录,将前面编译 《osg3.4在Windows上的编译(VS2015)》中的3rdParty和生成的OpenSceneGraph-3.4.0_install拷贝过来, 《gdal2.3在Windows上的编译(VS2015)》生成的gdal_install,参考《Proj5.0在Window上的编译(VS2015)》类似方法生成使用proj4相关代码生成proj4_install,参考《geos-3.8.0在Windows上的cmake编译(VS2015)》类似方法使用Geos3.7.0源代码生成Geos3.7.0_install目录文件拷贝到3rdParty目录中

d:
├─osgEarth2.10
    ├─osgEarth_build
    └─osgEarth_install
    └─osgearth-2.10
        └─third_party
             └─3rdParty
             └─gdal_install
             └─Geos3.7.0_install
             └─OpenSceneGraph-3.4.0_install
             └─Proj4_install

3.在osgearth-2.10目录下新建创建build.bat文件

@echo off
REM 定义源代码路径路径变量 
set src_dir="%cd%"
echo %src_dir%
REM 定义构建VisualStudio工程目录变量 
set build_dir="%cd%/../osgEarth_build"
REM 定义安装目录变量 
set install_dir="%cd%/../osgEarth_install"
REM 创建VisualStudio工程目录
mkdir %build_dir%
REM 创建安装目录
mkdir %install_dir%
REM 定义OSG_DIR
set OSG_DIR="%cd%/third_party/OpenSceneGraph-3.4.0_install"
REM CURL_INCLUDE_DIR
set CURL_INCLUDE_DIR="%cd%/third_party/3rdParty/include"
REM CURL_INCLUDE_DIR
set CURL_LIBRARY_DEBUG="%cd%/third_party/3rdParty/lib/libcurld.lib"
REM CURL_INCLUDE_DIR
set CURL_LIBRARY_RELEASE="%cd%/third_party/3rdParty/lib/libcurl.lib"

set GEOS_INCLUDE_DIR="%cd%/third_party/Geos3.7.0_install/include"
REM CURL_INCLUDE_DIR
set GEOS_LIBRARY_DEBUG="%cd%/third_party/Geos3.7.0_install/lib/geos_d.lib"
REM CURL_INCLUDE_DIR
set GEOS_LIBRARY="%cd%/third_party/Geos3.7.0_install/lib/geos.lib"

set GDAL_DIR="%cd%/third_party/gdal_install"

REM 定义cmake安装编译的类型
set CMAKE_BUILD_TYPE=Release
REM 定义cmake安装目录
set CMAKE_INSTALL_PREFIX=%install_dir%
REM 回到构建VisualStudio工程目录
cd %build_dir%
REM 调用camke命令行参数
cmake -G "Visual Studio 14 2015" -A x64   -S %src_dir%  -B %build_dir% -DOSG_DIR=%OSG_DIR% -DGDAL_DIR=%GDAL_DIR% -DCURL_INCLUDE_DIR=%CURL_INCLUDE_DIR% -DCURL_LIBRARY_DEBUG=%CURL_LIBRARY_DEBUG%  -DCURL_LIBRARY_RELEASE=%CURL_LIBRARY_RELEASE% -DGEOS_LIBRARY_DEBUG=%GEOS_LIBRARY_DEBUG% -DGEOS_LIBRARY=%GEOS_LIBRARY%  -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -DGEOS_INCLUDE_DIR=%GEOS_INCLUDE_DIR%  -DCMAKE_INSTALL_PREFIX=%CMAKE_INSTALL_PREFIX%                              
pause

最终文件目录如下:

d:
├─osgEarth2.10
    ├─osgEarth_build
    └─osgEarth_install
    └─osgearth-2.10
        └─build.bat
        └─third_party
             └─3rdParty
             └─gdal_install
             └─Geos3.7.0_install
             └─OpenSceneGraph-3.4.0_install
             └─Proj4_install

4.编译项目

1)启动VS2015 x64兼容命令提示符
2)拖动D:\osgEarth2.10\osgearth-2.10\build.bat文件到上面打开命令提示符中执行

3. 遇到的坑

1.因为开始用到的Geos3.8版本。
编译osgEarthSymbology报错

std::unique_ptr<geos::geom::CoordinateSequence,std::default_delete<_Ty>>”转换为“geos::geom::CoordinateSequence *”

在网上搜到解决版本发就是在src/osgEarthSymbology/GEOS.cpp加入如下代码


@@ -63,9 +63,13 @@ namespace{coords->push_back( coords->front() );}#if GEOS_VERSION_AT_LEAST(3,8)geom::CoordinateSequence::Ptr seq = factory->create(coords);return seq.get();

参考链接 后来觉得这样解决要修改源代码,又看了下源代码发现Geos3.6版本支持较好。就使用了geos3.6版本
最终使用3.7.0版本

2.Proj5.0
如何让编译的Proj的dll不带版本号?
因为osgEarth不认带版本号的dll.只认proj.dll
3.osgEarth生成的dll竟然放在了lib文件中
4.osgEarthViewerd 有警告消息

Warning: GraphicsWindowWin32::grabFocus() - Failed grabbing the focus

4.参考

OSGEarth2.8+Win10 64bit+VS2010编译

Windows下OSGEarth的编译过程

posted @ 2022-03-05 13:09  焦涛  阅读(840)  评论(0)    收藏  举报