Menu

#179 Detection of snprintf fails with VC14

None
closed-fixed
nobody
vc14 (1)
5
2015-09-15
2015-09-03
No

Due to the Universal CRT introduced in VC14 (aka Visual Studio 2015), check_function_exists() no longer works for detecting the presence of snprintf(). This leads to a linker error when using the library.

This patch fixed it for me:

diff --git a/cmake/modules/plplot.cmake b/cmake/modules/plplot.cmake
index 90aac62..7fea410 100644
--- a/cmake/modules/plplot.cmake
+++ b/cmake/modules/plplot.cmake
@@ -347,7 +347,11 @@ if(PL__HAVE_ISINF)
 endif(PL__HAVE_ISINF)

-check_function_exists(snprintf PL_HAVE_SNPRINTF)
+if(MSVC_VERSION EQUAL 1900)
+  set(PL_HAVE_SNPRINTF 1)
+else(MSVC_VERSION EQUAL 1900)
+  check_function_exists(snprintf PL_HAVE_SNPRINTF)
+endif(MSVC_VERSION EQUAL 1900)
 if(NOT PL_HAVE_SNPRINTF)
   check_function_exists(_snprintf _PL_HAVE_SNPRINTF)
   set(PL_HAVE_SNPRINTF ${_PL_HAVE_SNPRINTF} CACHE INTERNAL "Have function _sprintf")

Discussion

  • Torsten Martinsen

    Patch now as attachment.

     
  • Phil Rosenberg

    Phil Rosenberg - 2015-09-04

    It seems that snprintf and a number of other io related functions are now defined inline in stdio.h. This explains my linker errors above when shapelib was included - snprintf was not found because it is no longer in the library. The answer apparently is to use CheckSymbolExists instead as discussed at http://public.kitware.com/Bug/bug_relationship_graph.php?bug_id=15659&graph=relation.

    This has been changed as of commit ac0f09f9b69bcdc7812cfcda6c5902d8539da62a, by Alan Irwin.

    However, I don't think this is the direct case of the linker error. I could build a clean (with no external dependancies) version of plplot even without this fix in VS2015. I only got linker errors when I tried to build with shapelib. My shapelib was built as a static library statically linked to the runtime using VS2012, it therefore expects to find the definition of snprintf in the runtime, but it is not there in the VS2015 Runtime because it is defined inline. The fix is to build all static libraries with VS2015 (I'm not sure if dlls or libraries linked dynamically to the runtime need rebuilding) because VS does not guarentee consistent ABI accross versions.

    Torsten if you could provide us with the exact link error or confirm yourself that the link error is related to external libraries then I will close the bug. If this isn't the case then we need to look deeper.

     
  • Phil Rosenberg

    Phil Rosenberg - 2015-09-15

    Closing as I think this is ow fixed. Torsten, if the fix doesn't work for you please let us have the info above.

     
  • Phil Rosenberg

    Phil Rosenberg - 2015-09-15
    • status: open --> closed-fixed
    • Group: -->
     

Log in to post a comment.