Linker Error Building GDAL

折月煮酒 提交于 2019-12-05 01:50:55

问题


I am building GDAL from source using the MSVC 2015 64-bit command prompt. I am using Windows 8. Part way through the build, I get the following error:

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.

I have read on the Microsoft Site and GDAL Git issues section that this was a problem with the 2014 MSVC and pre-release version of MSVC 2015, but the issue was supposed to be resolved prior to the final release of MSVC 2015.

  • https://github.com/mapbox/windows-builds/issues/53
  • https://connect.microsoft.com/VisualStudio/feedback/details/1134693/vs-2015-ctp-5-c-vsnwprintf-s-and-other-functions-are-not-exported-in-appcrt140-dll-breaking-linkage-of-static-libraries

I don't seem to be the only person with this issue, but I am also not seeing a solution (besides reverting to an older version of MSVC such as 2013). Has anybody had any luck getting GDAL to build using MSVC 2015 (64 bit)?


回答1:


I edited nmake.opt:

I replaced line 667 ... :

!IFDEF ODBC_SUPPORTED  
ODBCLIB = odbc32.lib odbccp32.lib user32.lib  
!ENDIF

with:

!IFDEF ODBC_SUPPORTED  
!IF $(MSVC_VER) < 1900  
ODBCLIB = odbc32.lib odbccp32.lib user32.lib  
!ELSE  
ODBCLIB = legacy_stdio_definitions.lib odbc32.lib odbccp32.lib user32.lib  
!ENDIF  
!ENDIF

/Anders




回答2:


GDAL-2.1.0 already has a similar change on nmake.opt

!IFDEF ODBC_SUPPORTED
!IF $(MSVC_VER) >= 1900
# legacy_stdio_definitions.lib : https://connect.microsoft.com/VisualStudio/feedback/details/1134693/vs-2015-ctp-5-c-vsnwprintf-s-and-other-functions-are-not-exported-in-appcrt140-dll-breaking-linkage-of-static-libraries
ODBCLIB = legacy_stdio_definitions.lib odbc32.lib odbccp32.lib user32.lib
!ELSE
ODBCLIB = odbc32.lib odbccp32.lib user32.lib
!ENDIF
!ENDIF

but you must also specify the Visual Studio version from the command line with parameter MSVC_VER. e.g. for Visual Studio 2015 (MSVC_VER==1900) use this command line to compile

nmake -f makefile.vc MSVC_VER=1900



回答3:


In addition to the above, I also had to make the following modification to the nmake.opt file:

the line that says

!IFNDEF MSVC_VER
#assume msvc VS2008.
MSVC_VER=1500
!ENDIF

Should be changed to:

!IFNDEF MSVC_VER
#assume msvc VS2015.
MSVC_VER=1900
!ENDIF


来源:https://stackoverflow.com/questions/33266542/linker-error-building-gdal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!