All source releases are available for download from:
2.2.1 Latest Stable Release - June 2017
- http://download.osgeo.org/gdal/2.2.1/gdal221.zip - source as a zip (md5)
- http://download.osgeo.org/gdal/2.2.1/gdal-2.2.1.tar.gz - source as .tar.gz (md5)
- http://download.osgeo.org/gdal/2.2.1/gdal-2.2.1.tar.xz - source as .tar.xz (md5)
2.修改编译配置
在解压后的根目录下找到“nmake.opt”,
(1)配置成开发所用的VS版本
!IFNDEF MSVC_VER
#assume msvc VS2010.
MSVC_VER=1600
!ENDIF
下面是一些编译器版本的_MSC_VER值
Visual C++ 2015 MS VC++ 14.0 _MSC_VER = 1900
Visual C++ 2013 MS VC++ 12.0 _MSC_VER = 1800
Visual C++ 2010 MS VC++ 10.0 _MSC_VER = 1600
Visual C++ 2008 MS VC++ 9.0 _MSC_VER = 1500
Visual C++ 2005 MS VC++ 8.0 _MSC_VER = 1400
(2)配置GDAL安装路径
!IFNDEF GDAL_HOME
GDAL_HOME = "C:\gdal-runtime“
!ENDIF
(3)配置Python安装路径
!IFNDEF PYDIR
PYDIR = "C:\Python27"
!ENDIF
(4)64位开发配置
# Uncomment the following if you are building for 64-bit windows
# (x64). You'll need to have PATH, INCLUDE and LIB set up for 64-bit
# compiles.
WIN64=YES
(5)支持大于4G的TIF文件
# if using an external libtiff library
TIFF_INC = -Ic:/libtiff/libtiff
TIFF_LIB = c:/libtiff/lib/libtiff.lib
# uncomment following line, if you have libtiff version >= 4.0 to
# enable BigTIFF support
TIFF_OPTS= -DBIGTIFF_SUPPORT
3.编译源文件
点击开始--所有程序--Visual Studio 2010--Visual Studio x64 Win64 Command Prompt(2010),如下图所示:
进入源文件所在的文件夹,键入"cd E:\gdal-2.2.1",
键入"nmake /f makefile.vc"执行编译。
编译过程可能需要一些时间。
3.安装文件
(1)键入"nmake /f makefile.vc install"
E:\gdal-2.2.1>nmake /f makefile.vc install
执行完毕后,在设置好的配置文件夹 "C:\gdal-runtime“下增加了bin,data,及html文件夹。
可以看到:在文件夹bin已生成gdal201.dll文件(GDAL库的核心),这个DLL文件来执行实质性的操作。
(2)键入"nmake /f makefile.vc devinstall"执行完毕后,配置文件夹下增加了lib,include文件夹。这两个文件夹主要用于C及C++的开发。
4.配置VC++目录
在VS2010工程的属性中加入GDAL的include文件夹C:\gdal-runtime\include,在库目录添加lib文件夹C:\gdal-runtime\lib。
5. 测试
#include"gdal.h"
#include"gdal_priv.h"
CString fileStrName =_T("E:\\test064.jpg");
int len = WideCharToMultiByte( CP_ACP , 0 , fileStrName , fileStrName.GetLength() , NULL , 0 , NULL , NULL );
char* pAscii =new char[len+1];
len = WideCharToMultiByte( CP_ACP , 0 , fileStrName , fileStrName.GetLength() , pAscii , len+1 , NULL ,NULL );
pAscii[len] = 0;
const char* fileName = (const char*)pAscii;
GDALDataset *poDataset=NULL; //GDAL数据集
GDALAllRegister();
poDataset = (GDALDataset*)GDALOpen(fileName, GA_ReadOnly);
if (poDataset == NULL){
AfxMessageBox(_T("文件打开不成功"));
}
else{
AfxMessageBox(_T("文件打开成功"));
}
6. 开发错误调试
(1)找不到dll文件的错误,两种解决方案:
方法1、在环境变量 path中加入 ;
方法2、将找不到的dll文件都拷贝到Debug下。
(2)GDALOpen unresolved external symbol
error LNK2019: unresolved external symbol VSIFree
error LNK2019: unresolved external symbol "public: class CPLStringList
error LNK2019: unresolved external symbol CPLStrdup
error LNK2019: unresolved external symbol CSLFindString
error LNK2019: unresolved external symbol CSLPartialFindString
error LNK2019: unresolved external symbol CPLAtomicAdd
error LNK2019: unresolved external symbol GDALGetDataTypeSizeBytes
error LNK2019: unresolved external symbol GDALOpen
error LNK2019: unresolved external symbol GDALAllRegister
解决方案:
stdafx.h中添加一句:
#pragma comment(lib, "gdal_i.lib")