正文:
重要:gdal编译完是release版本的,工程中加载使用时release模式才能用,debug模式使用报错“错误LNK2038:检测到“_ITERATOR_DEBUG_LEVEL”的不匹配:值“0”与main.obj中的值“2”不匹配”,即使nmake时设置了debug=1,后继者注意这个坑。
工程加载使用时注意添加一个lib:#pragma comment(lib,"ws2_32.lib")
否则报错:error LNK2001: 无法解析的外部符号 __imp_*****
gdal1.10.1的版本编译有vs工程,可直接vs打开sln编译
编辑nmake.opt文件,MSVC_VER=1600

打开vs的工具命令,cd到gdal目录,执行以下任意一个nmake命令


新建 bin ,lib include文件夹;
把dll拷贝到bin, gdal.lib gdal_i.lib拷贝到lib,把所有.h头文件拷贝到include文件夹。
2.vs2010配置gdal
不讲了,太简单了:
1.添加include
2.添加lib;
附加依赖:gdal.lib gdal_i.lib
3.dll拷贝过来
再有问题留言吧
gdal test代码:
- #include "stdafx.h"
- #include
-
- using namespace std;
-
- #include "gdal_priv.h"
- //#pragma comment(lib,"gdal_i.lib")
- #pragma comment(lib,"ws2_32.lib")
- #include "ogr_geometry.h"
-
- int _tmain(int argc, _TCHAR* argv[])
- {
- GDALAllRegister();
- CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO");
- CPLSetConfigOption("USE_RRD","YES");
-
- const char* path = "D:\\H47F021001.tif";
-
- GDALDataset * poDataset = (GDALDataset *) GDALOpen(path, GA_ReadOnly);
- if(poDataset == NULL)
- {
- printf("open file fail.\n");
- return false;
- }
-
- int nImgWidth = poDataset -> GetRasterXSize();
- int nImgHeight = poDataset -> GetRasterYSize();
-
- int nBandnum = poDataset -> GetRasterCount();
-
- double *dGeoTrans = new double [6];
-
- poDataset -> GetGeoTransform(dGeoTrans);
-
- printf("Bandnum: %d \n", nBandnum);
- printf("ImgWidth: %d \n", nImgWidth);
- printf("ImgHeight: %d \n", nImgHeight);
-
- for (int i = 0; i < 6; ++i)
- {
- printf("GeoTrans %d : %.2f \n", i + 1, dGeoTrans[i]);
- }
-
- GDALClose(poDataset);
- delete [] dGeoTrans;
-
- system("pause");
- return 0;
- }