1. 程式人生 > >OpenCV使用CMake和MinGW-w64的編譯安裝

OpenCV使用CMake和MinGW-w64的編譯安裝

前言

而這篇博文是使用 64 位的 MinGW 編譯 OpenCV 生成 64 位的 dll。

因為博主沒有 64 位 qmake,所以沒勾選 WITH_QT

編譯好的 OpenCV(MinGW 版):

軟體環境

安裝 MinGW-w64 並配置環境變數

為系統(使用者)變數 Path 新增 E:\MinGW-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\bin

使用 CMake 生成 OpenCV 的 Makefile

開啟 cmake-gui,設定原始碼和生成路徑:

  • Where is the source code: E:/opencv_341/opencv/sources
  • Where to build the binaries: E:/opencv_341/opencv_mingw64_build

點選 Configure,設定編譯器

  • Specify the generator for this project: MinGW Makefiles
  • Specify native compilers
  • Next
  • Compilers C: E:\MinGW-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\bin\gcc.exe
  • Compilers C++: E:\MinGW-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\bin\g++.exe
  • Finish

編譯配置:

  • 勾選 WITH_OPENGL
  • 勾選 ENABLE_CXX11
  • 不勾選 WITH_IPP
  • 不勾選 ENABLE_PRECOMPILED_HEADERS

點選 Configure,Generate 生成 Makefile

博主的配置資訊如下:

General configuration for OpenCV 3.4.1 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2018-07-31T02:14:11Z
    Host:                        Windows 10.0.17134 AMD64
    CMake:                       3.12.0
    CMake generator:             MinGW Makefiles
    CMake build tool:            E:/MinGW-w64/x64-4.8.1-release-posix-seh-rev5/mingw64/bin/mingw32-make.exe
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (3 files):          + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (2 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (9 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

  C/C++:
    Built as dynamic libs?:      YES
    C++11:                       YES
    C++ Compiler:                E:/MinGW-w64/x64-4.8.1-release-posix-seh-rev5/mingw64/bin/g++.exe  (ver 4.8.1)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  E:/MinGW-w64/x64-4.8.1-release-posix-seh-rev5/mingw64/bin/gcc.exe
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--gc-sections  
    Linker flags (Debug):        -Wl,--gc-sections  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          opengl32 glu32
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann highgui imgcodecs imgproc java_bindings_generator ml objdetect photo python_bindings_generator shape stitching superres ts video videoio videostab
    Disabled:                    js world
    Disabled by dependency:      -
    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 python3 viz
    Applications:                tests perf_tests apps
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI: 
    Win32 UI:                    YES
    OpenGL support:              YES (opengl32 glu32)
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build (ver 90)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.34)
    TIFF:                        build (ver 42 - 4.0.9)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)

  Video I/O:
    Video for Windows:           YES
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (ver 57.107.100)
      avformat:                  YES (ver 57.83.100)
      avutil:                    YES (ver 55.78.100)
      swscale:                   YES (ver 4.8.100)
      avresample:                YES (ver 3.7.0)
    GStreamer:                   NO
    DirectShow:                  YES

  Parallel framework:            none

  Trace:                         YES (built-in)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  NVIDIA CUDA:                   NO

  OpenCL:                        YES (no extra features)
    Include path:                E:/opencv_341/opencv/sources/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            E:/Python37-32/python.exe

  Java:                          
    ant:                         NO
    JNI:                         C:/Program Files (x86)/Java/jdk1.8.0_181/include C:/Program Files (x86)/Java/jdk1.8.0_181/include/win32 C:/Program Files (x86)/Java/jdk1.8.0_181/include
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:                        NO

  Install to:                    E:/opencv_341/opencv_mingw64_build/install
-----------------------------------------------------------------

Configuring done
Generating done

編譯 OpenCV

開啟終端進行編譯:(-j 是使用 8 個執行緒進行編譯,請根據你的計算機配置合理設定執行緒數)

E:
cd E:\opencv_341\opencv_mingw64_build
mingw32-make -j 8
mingw32-make install

如果 mingw32-make -j 8 遇到錯誤,請看下面的 編譯 OpenCV 常見錯誤,否則執行 mingw32-make install,完成安裝。

編譯 OpenCV 常見錯誤

1. MinGW-w64 的 aviriff.h 檔案註釋錯誤

表現

[ 49%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_dshow.cpp.obj
In file included from E:\opencv_341\opencv\sources\modules\videoio\src\cap_dshow.cpp:113:0:
e:\mingw-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\x86_64-w64-mingw32\include\aviriff.h:2:8: error: expected constructor, destructor, or type conversion before 'file'
 * This file is part of the mingw-w64 runtime package.
        ^
e:\mingw-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\x86_64-w64-mingw32\include\aviriff.h:3:25: error: 'refer' does not name a type
 * No warranty is given; refer to the file DISCLAIMER within this package.
                         ^
In file included from e:\mingw-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\x86_64-w64-mingw32\include\aviriff.h:19:0,
                 from E:\opencv_341\opencv\sources\modules\videoio\src\cap_dshow.cpp:113:
e:\mingw-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\x86_64-w64-mingw32\include\pshpack2.h:7:21: error: expected declaration before end of line
 #pragma pack(push,2)
                     ^
modules\videoio\CMakeFiles\opencv_videoio.dir\build.make:146: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_dshow.cpp.obj' failed
mingw32-make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_dshow.cpp.obj] Error 1
CMakeFiles\Makefile2:3057: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
mingw32-make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

MinGW-w64_aviriff.h_file_annotation_error

解決

開啟E:\MinGW-w64\x64-4.8.1-release-posix-seh-rev5\mingw64\x86_64-w64-mingw32\include\aviriff.h

發現第一行的多行註釋少了個/符號,加上儲存,如下:

/**
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER within this package.
*/

然後重新 Configure-Generate-mingw32-make 就好了。

2. cap_msmf.cpp capture code 錯誤【2018年10月13日修改,因編譯 OpenCV-4.0.0-alpha 時遇到並解決】

表現

......
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp: In member function 'HRESULT {anonymous}::ComPtr<T>::As({anonymous}::ComPtr<U>&) const [with U = IMF2DBuffer; T = IMFMediaBuffer; HRESULT = long int]':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp:172:5: error: control reaches end of non-void function [-Werror=return-type]
     }
     ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp: In member function 'T* {anonymous}::ComPtr<T>::operator->() const [with T = IMF2DBuffer]':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp:149:5: error: control reaches end of non-void function [-Werror=return-type]
     }
     ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp: In member function 'T* {anonymous}::ComPtr<T>::operator->() const [with T = IMFMediaBuffer]':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp:149:5: error: control reaches end of non-void function [-Werror=return-type]
     }
     ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp: In member function 'T* {anonymous}::ComPtr<T>::operator->() const [with T = IMFSinkWriter]':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp:149:5: error: control reaches end of non-void function [-Werror=return-type]
     }
     ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp: In member function 'T* {anonymous}::ComPtr<T>::Get() const [with T = IMFMediaBuffer]':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\videoio\src\cap_msmf.cpp:158:5: error: control reaches end of non-void function [-Werror=return-type]
     }
     ^
cc1plus.exe: some warnings being treated as errors
modules\videoio\CMakeFiles\opencv_videoio.dir\build.make:188: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_msmf.cpp.obj' failed
mingw32-make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_msmf.cpp.obj] Error 1
CMakeFiles\Makefile2:2556: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
mingw32-make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
mingw32-make[1]: *** Waiting for unfinished jobs....
[ 58%] Linking CXX shared library ..\..\bin\libopencv_dnn400.dll
[ 59%] Built target opencv_dnn
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

原因

解決

所以,在 cmake-gui 編譯配置中:

  • 不勾選 WITH_MSMF

然後重新 Configure-Generate-mingw32-make

3. ‘M_PI’ was not declared in this scope 錯誤【2018年10月13日修改,因編譯 OpenCV-4.0.0-alpha 時遇到並解決】

表現

[ 86%] Building CXX object modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/chessboard.cpp.obj
In file included from E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:7:0:
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.hpp: In constructor 'cv::details::FastX::Parameters::Parameters()':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.hpp:35:36: error: 'M_PI' was not declared in this scope
                 resolution = float(M_PI*0.25);
                                    ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: At global scope:
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:25:42: error: 'M_PI' was not declared in this scope
 const float MAX_ANGLE = float(48.0/180.0*M_PI);          // max angle between line segments supposed to be straight
                                          ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:26:48: error: 'M_PI' was not declared in this scope
 const float MIN_COS_ANGLE = float(cos(35.0/180*M_PI));   // min cos angle between board edges
                                                ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:29:35: error: 'M_PI' was not declared in this scope
 const float RAD2DEG = float(180.0/M_PI);
                                   ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In function 'int cv::details::testPointSymmetry(cv::Mat, cv::Point2f, float, float)':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:217:33: error: 'M_PI' was not declared in this scope
     for(double angle=0;angle <= M_PI;angle+=M_PI*0.1)
                                 ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In member function 'void cv::details::FastX::rotate(float, const cv::Mat&, cv::Size, cv::Mat&) const':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:287:110: error: 'M_PI' was not declared in this scope
         cv::Mat m = cv::getRotationMatrix2D(cv::Point2f(float(img.cols*0.5),float(img.rows*0.5)),float(angle/M_PI*180),1);
                                                                                                              ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In member function 'std::vector<std::vector<float> > cv::details::FastX::calcAngles(const std::vector<cv::Mat>&, std::vector<cv::KeyPoint>&) const':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:393:30: error: 'M_PI' was not declared in this scope
     float resolution = float(M_PI/channels);
                              ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In member function 'void cv::details::FastX::detectImpl(const cv::Mat&, std::vector<cv::Mat>&, std::vector<cv::Mat>&, const cv::Mat&) const':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:631:30: error: 'M_PI' was not declared in this scope
         int num = int(0.5001*M_PI/parameters.resolution);
                              ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In member function 'void cv::details::Ellipse::draw(cv::InputOutputArray, const Scalar&) const':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:721:43: error: 'M_PI' was not declared in this scope
     cv::ellipse(img,center,axes,360-angle/M_PI*180,0,360,color);
                                           ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In static member function 'static float cv::details::Chessboard::Board::findMaxPoint(cv::flann::Index&, const cv::Mat&, const cv::details::Ellipse&, float, float, cv::Point2f&)':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:1541:17: error: 'M_PI' was not declared in this scope
         if(a1 > M_PI*0.5)
                 ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:1543:16: error: 'M_PI' was not declared in this scope
         if(a2> M_PI*0.5)
                ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In static member function 'static bool cv::details::Chessboard::Board::estimateSearchArea(const Point2f&, const Point2f&, const Point2f&, float, cv::details::Ellipse&, const Point2f*)':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:1787:28: error: 'M_PI' was not declared in this scope
         angle = float(2.0F*M_PI-angle);
                            ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In member function 'void cv::details::Chessboard::findKeyPoints(const cv::Mat&, std::vector<cv::KeyPoint>&, std::vector<cv::Mat>&, std::vector<std::vector<float> >&, const cv::Mat&) const':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:2793:29: error: 'M_PI' was not declared in this scope
     para.resolution = float(M_PI*0.25);   // this gives the best results taking interpolation into account
                             ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In member function 'cv::Mat cv::details::Chessboard::buildData(const std::vector<cv::KeyPoint>&) const':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:2844:30: error: 'M_PI' was not declared in this scope
         (*val++) = float(2.0*M_PI-iter->angle/180.0*M_PI);
                              ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp: In member function 'std::vector<cv::KeyPoint> cv::details::Chessboard::getInitialPoints(cv::flann::Index&, const cv::Mat&, const cv::KeyPoint&, float, float, float) const':
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:2874:25: error: 'M_PI' was not declared in this scope
         if(angle_temp > M_PI*0.5)
                         ^
E:\opencv-4.0.0-alpha\opencv-4.0.0-alpha\modules\calib3d\src\chessboard.cpp:2879:29: error: 'M_PI' was not declared in this scope
             if(angle_temp > M_PI*0.5)
                             ^
modules\calib3d\CMakeFiles\opencv_calib3d.dir\build.make:137: recipe for target 'modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/chessboard.cpp.obj' failed
mingw32-make[2]: *** [modules/calib3d/CMakeFiles/opencv_calib3d.dir/src/chessboard.cpp.obj] Error 1
CMakeFiles\Makefile2:3018: recipe for target 'modules/calib3d/CMakeFiles/opencv_calib3d.dir/all' failed
mingw32-make[1]: *** [modules/calib3d/CMakeFiles/opencv_calib3d.dir/all] Error 2
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

原因

因為 OpenCV 在 chessboard.cppchessboard.hpptest_chesscorners.cpp 這些程式碼中有 BUG,使用的應該是 CV_PI 而不是 M_PI 導致的。具體見我提的 Issue:Failed to compile opencv-4.0.0-alpha using mingw-w64

解決

然後重新 Configure-Generate-mingw32-make

4. ‘posix_memalign’ was not declared in this scope 錯誤【2018年11月17日修改,因編譯 OpenCV-4.0.0-rc 時遇到並解決】

表現

[ 28%] Building CXX object modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1c/sources/ade/source/alloc.cpp.obj
E:\opencv-4.0.0-rc\opencv-4.0.0-rc-build\3rdparty\ade\ade-0.1.1c\sources\ade\source\alloc.cpp: In function 'void* ade::aligned_alloc(std::size_t, std::size_t)':
E:\opencv-4.0.0-rc\opencv-4.0.0-rc-build\3rdparty\ade\ade-0.1.1c\sources\ade\source\alloc.cpp:31:16: error: 'posix_memalign' was not declared in this scope
     auto res = posix_memalign(&ret, std::max(sizeof(void*), alignment), size);
                ^~~~~~~~~~~~~~
mingw32-make[2]: *** [modules\CMakeFiles\ade.dir\build.make:63: modules/CMakeFiles/ade.dir/__/3rdparty/ade/ade-0.1.1c/sources/ade/source/alloc.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:884: modules/CMakeFiles/ade.dir/all] Error 2
mingw32-make: *** [Makefile:162: all] Error 2

2018-11-17_174118.png

原因

解決

opencv-4.0.0-rc-build\3rdparty\ade\ade-0.1.1c\sources\ade\source\alloc.cpp 檔案的所有 WIN32 改為 _WIN32,如這個 PR 所做的修改:fix check for win32 #6

然後重新 Configure-Generate-mingw32-make

其他錯誤

如果以上錯誤不是你所遇到的,請務必先看下面兩個文章中的錯誤。

更新日誌

  1. 2018年10月13日為 OpenCV-4.0.0-alpha 而修改,主要改了 “編譯 OpenCV 常見錯誤”
  2. 2018年11月17日為 OpenCV-4.0.0-rc 而修改,主要改了 “編譯 OpenCV 常見錯誤”