OpenCV:io_win32.cc:_wfopen尚未被声明为MinGW

时间:2018-09-23 19:04:43

标签: c++ opencv cmake mingw

我尝试使用OpenCVTDM MinGW (5.1.0)附带的code blocks (32 bit)从源代码构建CMake,而运行mingw32-make时却得到{{1} }错误。

io_win32.cc : _wfopen has not been declared

搜索了一段时间后,我发现this link指出[ 0%] Built target gen-pkgconfig [ 2%] Built target zlib [ 5%] Built target libjpeg-turbo [ 7%] Built target libtiff [ 15%] Built target libwebp [ 18%] Built target libjasper [ 19%] Built target libpng [ 24%] Built target IlmImf [ 24%] Building CXX object 3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj D:\Programs\OpenCV-Source\opencv\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc: In function 'FILE* google::protobuf::internal::win32::fopen(const char*, const char*)': D:\Programs\OpenCV-Source\opencv\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:330:10: error: '::_wfopen' has not been declared return ::_wfopen(wpath.c_str(), wmode.c_str()); ^ 3rdparty\protobuf\CMakeFiles\libprotobuf.dir\build.make:258: recipe for target '3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj' failed mingw32-make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/io_win32.cc.obj] Error 1 CMakeFiles\Makefile2:715: recipe for target '3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all' failed mingw32-make[1]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all] Error 2 Makefile:161: recipe for target 'all' failed mingw32-make: *** [all] Error 2 是在wfopen下定义的

wchar.h

我不确定他们在链接中谈论的#ifdef __MSVCRT__ _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW fgetws (wchar_t*, int, FILE*); _CRTIMP int __cdecl __MINGW_NOTHROW fputws (const wchar_t*, FILE*); _CRTIMP wint_t __cdecl __MINGW_NOTHROW getwc (FILE*); _CRTIMP wint_t __cdecl __MINGW_NOTHROW getwchar (void); _CRTIMP wint_t __cdecl __MINGW_NOTHROW putwc (wint_t, FILE*); _CRTIMP wint_t __cdecl __MINGW_NOTHROW putwchar (wint_t); #ifndef __STRICT_ANSI__ _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _getws (wchar_t*); _CRTIMP int __cdecl __MINGW_NOTHROW _putws (const wchar_t*); _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfdopen(int, const wchar_t *); _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfopen (const wchar_t*, const wchar_t*); _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfreopen (const wchar_t*, const wchar_t*, FILE*); _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wfsopen (const wchar_t*, const wchar_t*, int); _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtmpnam (wchar_t*); _CRTIMP wchar_t* __cdecl __MINGW_NOTHROW _wtempnam (const wchar_t*, const wchar_t*); _CRTIMP int __cdecl __MINGW_NOTHROW _wrename (const wchar_t*, const wchar_t*); _CRTIMP int __cdecl __MINGW_NOTHROW _wremove (const wchar_t*); _CRTIMP void __cdecl __MINGW_NOTHROW _wperror (const wchar_t*); _CRTIMP FILE* __cdecl __MINGW_NOTHROW _wpopen (const wchar_t*, const wchar_t*); #endif /* __STRICT_ANSI__ */ #endif /* __MSVCRT__ */ 选项的添加方式和位置。 无论如何,有人可以帮助我解决这个问题吗?任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

我不知道该如何简化它,我因不简化而被否决。
无论如何,在NETWORK_PASSPHRASE="my private network" NODE_SEED=<pod0_private_key> KNOWN_PEERS=[ "stellar-0", "stellar-1", "stellar-2"] [QUORUM_SET] VALIDATORS=[ <pod1_pub_key>, <pod2_pub_key> ] 中,如果我通过移除wchar.h来放置#ifdef __STRICT_ANSI__,则它运行得很好。我不知道这是正确的方法还是无效,但是有效!

更新

上面的方法确实可以工作,但是由于opencv源文件中使用了许多非ANSI方法,因此每次遇到此类方法时,编译器都会开始抱怨。因此,最好在我们构建源的#ifndef __STRICT_ANSI__中设置CMAKE_CXX_FLAGS:STRING=-U__STRICT_ANSI__标志。这样更合适,更省力。

答案 1 :(得分:0)

我也在构建OpenCV,并且遇到相同的问题。首先,我看一下文件io_win32.cc:

FILE* fopen(const char* path, const char* mode) {
#ifdef SUPPORT_LONGPATHS
  if (null_or_empty(path)) {
    errno = EINVAL;
    return NULL;
  }
  wstring wpath;
  if (!as_windows_path(path, &wpath)) {
    errno = ENOENT;
    return NULL;
  }
  wstring wmode;
  if (!strings::utf8_to_wcs(mode, &wmode)) {
    errno = EINVAL;
    return NULL;
  }
  return ::_wfopen(wpath.c_str(), wmode.c_str()); //the error
#else
  return ::fopen(path, mode);
#endif
}

通过在同一文件io_win32.cc中禁用SUPPORT_LONGPATHS,似乎可以使用fopen代替_wfopen:

// Comment this out to fall back to using the ANSI versions (open, mkdir, ...)
// instead of the Unicode ones (_wopen, _wmkdir, ...). Doing so can be useful to
// debug failing tests if that's caused by the long path support.
#define SUPPORT_LONGPATHS

如果您对SUPPORT_LONGPATHS感到好奇:https://www.itprotoday.com/windows-10/enable-long-file-name-support-windows-10。基本上,它支持长文件名,最多32,767个字符。