6

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.

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)?

rmkemker
  • 470
  • 5
  • 16

3 Answers3

7

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
escolano
  • 101
  • 1
  • 2
6

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

Martin Valgur
  • 5,793
  • 1
  • 33
  • 45
  • For a reference https://connect.microsoft.com/VisualStudio/feedback/details/1039102 – Kelly Elton Dec 07 '15 at 21:40
  • It did build and got rid of the linker error. I am going to install the python bindings and try it out. Thanks! – rmkemker Jan 02 '16 at 15:30
  • The build worked...I am using it with Python support (built the Python bindings separate from https://pypi.python.org/pypi/GDAL/) which was relatively easy. Thanks for your help! – rmkemker Jan 05 '16 at 13:51
0

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
SteveEng
  • 331
  • 2
  • 6