編譯OpenCV時出現的一些問題
阿新 • • 發佈:2019-01-04
D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:94:3: warning: identifier 'nullptr' is a keyword in C++11 [-Wc++0x-compat] return s == nullptr || *s == 0; ^ D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc: In function 'bool google::protobuf::internal::win32::{anonymous}::null_or_empty(const char_type*)': D:\opencv-3.4.1\opencv-3.4.1\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc:94:15: error: 'nullptr' was not declared in this scope return s == nullptr || *s == 0; ^ 3rdparty\protobuf\CMakeFiles\libprotobuf.dir\build.make:412: 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:710: 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
解決方案:
在 cmake-gui 編譯配置中:
勾選 ENABLE_CXX11
然後重新Configure
-Generate
-mingw32-make
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
解決方案:
修改E:\OpenCV_3.3.1\opencv\sources\modules\videoio\src\cap_dshow.cpp
檔案,在#include "DShow.h"
這行的上面加一行#define NO_DSHOW_STRSAFE
然後重新Configure
Generate
-mingw32-make
D:\SoftwareRoot\opencv\sources\3rdparty\protobuf\src\google\protobuf\stubs\io_win32.cc: In function 'FILE* google::protobuf::internal::win32::fopen(const char*, const char*)': D:\SoftwareRoot\opencv\sources\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:687: 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
解決方案:
修改D:\SoftwareRoot\opencv\MinGW_OpenCV中的CMakeCache.txt,查詢CMAKE_CXX_FLAGS,然後把CMAKE_CXX_FLAGS:STRING的值修改為-U__STRICT_ANSI__,如CMAKE_CXX_FLAGS:STRING=-U__STRICT_ANSI__
注意一定不要重新Configure
-Generate
!!
做了這步操作之後CMakeCache.txt又會重新生成。直接mingw32-make
這裡的MinGW_OpenCV是CMake生成的資料夾。
還好只遇到了三個問題……什麼都不懂裝了好幾天Orz。
我的OpenCV版本是3.4.1
=====================使用QT時pro檔案需要新增的程式碼================
INCLUDEPATH += D:/SoftwareRoot/opencv/release/include \
D:/SoftwareRoot/opencv/release/include/opencv \
D:/SoftwareRoot/opencv/release/include/opencv2
LIBS += D:/SoftwareRoot/opencv/release/install/x86/mingw/lib/libopencv_*