2016.07.13 22:07 "[Tiff] Visual Studio 2012: snprintf problem when linking with libtiff.lib", by Bart Vandewoestyne

2016.07.13 22:07 "[Tiff] Visual Studio 2012: snprintf problem when linking with libtiff.lib", by Bart Vandewoestyne

Hello list,

I am building LibTIFF 4.0.6 with Visual Studio 2012, using the nmake approach from http://www.remotesensing.org/libtiff/build.html#PC. I now try to link my own program with libtiff by making sure that libtiff.lib is found at link time. However, I get the error:

libtiff.lib(tif_dirinfo.obj): error LNK2019: unresolved external symbol __TIFF_snprintf_f referenced in function __TIFFCreateAnonField

I noticed that in the function _TIFFCreateAnonField from libtiff/tif_dirinfo.c a call to snprintf is made, which according to https://msdn.microsoft.com/en-us/library/2ts7cx93(v=vs.110).aspx is not available in Visual Studio 2012. I also noticed a workaround is being given in port/snprintf.c. However, I'm not sure if I'm correctly using the workaround. In order to get my application to link with libtiff, I also had to make sure that libport.lib was linked in, by adding it to the list of libraries to link with, and by adding the port directory to the list of directories to search for libraries. So next to linking with libtiff.lib, I'm also linking with libport.lib.

Is this the correct and recommended way of working around the snprintf problem? Can't I just link with libtiff.lib alone? I thought that would work, because `dumpbin /symbols libport.lib | findstr __TIFF_snprintf_f` gives:

    00C 00000000 SECT4  notype ()    External     | __TIFF_snprintf_f

which i think means that the symbol is available in libport.lib, but next to that, `dumpbin /symbols libtiff.lib | findstr __TIFF_snprintf_f` gives:

    00C 00000000 SECT4  notype ()    External     | __TIFF_snprintf_f
    0FC 00000000 UNDEF  notype ()    External     | __TIFF_snprintf_f

Here, I do not understand why __TIFF_snprintf_f is being reported twice: once in Section 4 and once as Undefined. Clearly, I need more understanding of the COFF symbol table to understand why libtiff.lib is not enough for linking... or should it?

Kind regards,
Bart