Spatialite编译(VS2019)与调用依赖
编译环境
官网: http://www.gaia-gis.it/gaia-sins/
官方编译文档: http://www.gaia-gis.it/gaia-sins/msvc_how_to.html (已提供源码和重要依赖库的下载地址)
官方API文档: http://www.gaia-gis.it/gaia-sins/splite-doxy-5.0.1.pdf
编译环境:
VS2019 x64
使用工具:x64 Native Tools Command Prompt for VS2019
nmake编译
编译后的结果
- 生成到指定的 OSGeo4W目录下(目录结构如下)
- 外部使用时,所有依赖到的库:
与GDAL公用的库:proj、geos、sqlite3
其它基础库:zlib、iconv、libxml2
需要新编的库:librttopo、freexl
最终编译的库:spatialite
编译过程
- 与GDAL公用的库直接拷到之前定的OSGeo4W目录下即可
注意目录规范如上图:bin、include、lib、share
- 其它基础库
推荐使用osgeo4w-setup.exe工具直接下载development的库即可。
工具链接: https://trac.osgeo.org/osgeo4w/
指定必要的安装路径,方法如下图所示:
点击“View”按钮后进入如下界面,在Search后输入需要下载的库,它会自动进行搜索,以zlib为例:
注意使用“development”那一行,点击Skip,就加入下载列表了。接下来就是其它的库,类似的搜索,选择,点击Skip
选好后点击“下一页”,就开始下载,最后的下载结果会生成到选择的目录下,以lib、bin、include、share的方式组织。
- 需要新编的库,以及最终编译spatialite库
在官方编译文档里下载源码,用nmake进行编译,在编译前需要修改一些配置,以及注意使用x64还是x86,要统一。
以freexl为例,编译VS2019的x64版本(其它依赖库,以及Spatialite库同理):
- 修改nmake64.opt的编译完成后的安装路径
- 修改makefile64.vc需要依赖的库的路径
- 执行nmake命令
nmake /f makefile64.vc clean
nmake /f makefile64.vc
nmake /f makefile64.vc install
API-Demo调用
建立新工程后,引入spatialite.lib库,并调用API。
VS工程配置include寻址目录以及依赖库:
- 目录都定位到之前生成的“xxx\OSGeo4W”下
- 头文件:xxx\OSGeo4W\include
- 依赖库:xxx\OSGeo4W\lib
调用Version-API,测试编译结果:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <spatialite/gaiaconfig.h>
#include <geos_c.h>
#include <sqlite3.h>
#include <spatialite.h>
int main(int argc, char* argv[])
{
std::string strVersion = spatialite_version();
std::cout << strVersion << std::endl;
return 0;
}