VS2015编译64位GDAL

        使用VS2015编译64位的GDAL时容易遇到一些问题,特总结如下。


        1.下载gdal-2.0.3(也可以下载其他版本),并解压

         解压后的文件中应该有一个nmake.opt文件,在编译之前需要修改nmake.opt中的一些配置。

       (a).可以先在nmake.opt文件中看下该GDAL版本是否支持VS2015。

        (b).GDAL_HOME = “C:\warmerda\bld”,大约在62行,编译后的生成的头文件、静态库、动态库将会存储到这个路径,可以修改。
       (c).”#WIN64=YES”,大约在172行,编译64位GDAL时,要删除前面的#。修改MSVC_VER的值,改为1900

       2.编译
       (a).打开VS2015命令行,开始菜单->所有程序,找到VS2015,我选择的是VS2015 ×64 本机工具命令提示符              

        (b). 打开到GDAL解压文件所在的目录(有makefile.vc的目录),我直接在D盘解压了,所以如下图所示      
                     
       
         (c).依次输入下面的命令
           nmake -f makefile.vc
           nmake /f makefile.vc install
           nmake /f makefile.vc devinstal

          第一个命令是编译GDAL,第二个、第三个命令是将生成的头文件、静态库、动态库存储到GDAL_HOME目录。

          每个命令输入后需要等几分钟。

          **运行完第一个命令后可能会遇到这样的问题(网上截的图,但问题是一样的):


  
  
  1. Creating library gdal_i.lib and object gdal_i.exp  
  2. odbccp32.lib(dllload.obj) : error LNK2019: unresolved external symbol _vsnwprintf_s referenced in function StringCchPrintfW  
  3. gdal201.dll : fatal error LNK1120: 1 unresolved externals  
  4. NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.EXE"' : return code '0x460'  
  5. Stop.   
Creating library gdal_i.lib and object gdal_i.exp
odbccp32.lib(dllload.obj) : error LNK2019: unresolved external symbol _vsnwprintf_s referenced in function StringCchPrintfW
gdal201.dll : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.EXE"' : return code '0x460'
Stop. 


解决方法是把nmake.opt文件中的,大约在220行

  
  
  1. # Comment out the following to disable ODBC support.  
  2. ODBC_SUPPORTED = 1  
# Comment out the following to disable ODBC support.
ODBC_SUPPORTED = 1

    替换成

  
  
  1. # Comment out the following to disable ODBC support.  
  2. ODBC_SUPPORTED = 1  
# Comment out the following to disable ODBC support.

# ODBC_SUPPORTED = 1

   就是把ODBC支持注释掉。


 
 
 

       3.编译成功后在VS2015中配置       (a).打开解决方案资源管理器中项目的属性界面  

                                                                                         
      
 

      (b).添加C:\warmerda\bld\include文件,在“VC++”目录中的“包含目录”中添加include文件,“库目录”中添加lib文件,如下图所示:

 


      (c).在“链接器”->“输入”的“附加依赖项”中键入gdal_i.lib

     
     

4.测试 新建控制台程序,输入下面的代码,运行成功,配置完成。

  
  
  1. #include “stdafx.h”  
  2. #include “gdal_priv.h”  
  3. #include<iostream>  
  4. using namespace std;  
  5. int main()  
  6. {  
  7.     GDALAllRegister();  
  8.     const char* img = “test.jpg”;   //在项目文件夹下储存一张影像  
  9.     GDALDataset *poDataset = (GDALDataset*)GDALOpen(img, GA_ReadOnly);  
  10.     if (poDataset == nullptr)  
  11.         cout << ”测试失败” << endl;  
  12.     return 0;  
  13. }  
#include "stdafx.h"




#include "gdal_priv.h" #include<iostream> using namespace std; int main() { GDALAllRegister(); const char* img = "test.jpg"; //在项目文件夹下储存一张影像 GDALDataset *poDataset = (GDALDataset*)GDALOpen(img, GA_ReadOnly); if (poDataset == nullptr) cout << "测试失败" << endl; return 0; }

出现的问题:
(a).出现下面错误

  

      配置错误,需要在 ×64下重新配置。

    
     

      (b).缺少dll文件,将C:\warmerda\bld\bin 中的 gdal200.dll 复制到项目下的exe类型的文件目录中。

      


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值