Just got the same error and fixed it by adding the following line to CMakelists.txt:
SET(CMAKE_REQUIRED_LIBRARIES legacy_stdio_definitions.lib). It is cmake bug https://cmake.org/Bug/view.php?id=15659