Error C4996: 'fopen': This function or variable may be unsafe. in VS2015.

System information (version)

  • OpenCV => 3.2.0 rc (Latest version)
  • Operating System / Platform => Windows10 64bit
  • Compiler => Visual Studio 2015 Update3

Detailed description

Source: %OPENCV_PATH%\include\opencv2\flann\logger.h 67
Error C4996 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Steps to reproduce

Build below code with opencv_flann.

#include <Windows.h>
#include <opencv2/opencv.hpp>

void main(int argc, char* argv[])
{
}

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nCmd)
{
    main(0,NULL);
}

logger.h : Original code.

stream = fopen(name,"w");
if (stream == NULL) {
    stream = stdout;
}

logger.h : Fixed code.

 #if _MSC_VER >= 1500
     errno_t error;
     error = fopen_s(&stream, name, "w");
     if (error != 0) {
         stream = stdout;
     }
 #else
     stream = fopen(name,"w");
     if (stream == NULL) {
         stream = stdout;
     }
 #endif

猜你喜欢

转载自blog.csdn.net/u010440456/article/details/84347669