Opencv mutex error

I'm trying to set up OpenCV, some basic code to just start with it and see what I can do. But every time I try to compile the app, I get errors saying 'Mutex' is not a member of 'cv'. Tried some of

I’m trying to set up OpenCV, some basic code to just start with it and see what I can do. But every time I try to compile the app, I get errors saying
'Mutex' is not a member of 'cv'. Tried some of other solutions, for eg. this

My environment is VS Code with c_cpp_properties.json set as this:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}",
                "C:\MinGW\lib\gcc\mingw32\8.2.0\include\c++",
                "C:\MinGW\lib\opencv\build\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:\MinGW\posix\mingw64\bin\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
            "browse": {
                "path": [
                    "${workspaceFolder}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 4
}

Tried few reinstalls of g++ and all that minGW stuff, nothing works.

That’s my code of main.cpp:

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp> 
#include <string> 
#include <iostream> 

using namespace cv; 
using namespace std; 

int main() 
{ 
    const string file_name = "sunflower.jpg"; 
    Mat img = imread(file_name); 
    if( !img.data ) 
    { 
        cout << "Nie odnalezionu pliku " << file_name; 
        return -1; 
    } 
    const string window_name = "OpenCV_1"; 
    namedWindow(window_name, WINDOW_AUTOSIZE); 
    imshow(window_name, img); 
    waitKey(0); 
    return 0; 
}

Console output

 Executing task: g++ -g -o bin/debug.exe src/main.cpp -IC:MinGWlibopencvbuildinclude -LC:MinGWlibopencvbuildx64vc15bin -llibopencv_highgui242 -llibopencv_features2d242 -llibopencv_flann242 -llibopencv_objdetect242 -llibopencv_video242 -llibopencv_calib3d242 -llibopencv_contrib242 -llibopencv_imgproc242 -llibopencv_core242 -llibopencv_ml242 -llibopencv_legacy242 -llibopencv_nonfree242 -llibopencv_photo242 -llibopencv_stitching242 -llibopencv_videostab242 <

In file included from C:MinGWlibopencvbuildinclude/opencv2/core.hpp:3290,
                 from C:MinGWlibopencvbuildinclude/opencv2/highgui.hpp:46,
                 from C:MinGWlibopencvbuildinclude/opencv2/highgui/highgui.hpp:48,
                 from src/main.cpp:1:
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:697:14: error: 'recursive_mutex' in namespace 'std' does not name a type
 typedef std::recursive_mutex Mutex;
              ^~~~~~~~~~~~~~~
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:697:9: note: 'std::recursive_mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:60:1:
+#include <mutex>

C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:697:9:
 typedef std::recursive_mutex Mutex;
         ^~~
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:29: error: 'Mutex' is not a member of 'cv'
 typedef std::lock_guard<cv::Mutex> AutoLock;
                             ^~~~~
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:29: note: suggested alternative: 'Matx'
 typedef std::lock_guard<cv::Mutex> AutoLock;
                             ^~~~~
                             Matx
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:29: error: 'Mutex' is not a member of 'cv'
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:29: note: suggested alternative: 'Matx'
 typedef std::lock_guard<cv::Mutex> AutoLock;
                             ^~~~~
                             Matx
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:34: error: template argument 1 is invalid
 typedef std::lock_guard<cv::Mutex> AutoLock;
                                  ^
The terminal process terminated with exit code: 1

I’m in need of a solution to configure g++ in a way to compile the application. Or do something I’m yet not aware of.

Comments

@tenderZeitGeist

Hi there,
I am trying to compile OpenCV for my systems with MinGW 7.2.0., configured as win32 and CMake 3.10. But since half a week I got this error and I tried a lot, googled a lot and now kinda at the wit’s end. Most solutions are seem so simple, yet this specify problem got questioned very rarely and there is no real solution to it, which is why I am raising this issue.

Thanks in advance!

Here is the log from the compiling process:

E:Applicationopencvmingw-build>mingw32-make
[  0%] Built target gen-pkgconfig
[  2%] Built target zlib
[  6%] Built target libtiff
[ 10%] Built target libjpeg
[ 19%] Built target libwebp
[ 22%] Built target libjasper
[ 23%] Built target libpng
[ 29%] Built target IlmImf
[ 35%] Built target libprotobuf
[ 40%] Built target opencv_core
[ 46%] Built target opencv_imgproc
[ 48%] Built target opencv_imgcodecs
[ 49%] Built target opencv_videoio
[ 49%] Built target opencv_highgui
[ 50%] Built target opencv_ts
[ 52%] Built target opencv_test_core
[ 55%] Built target opencv_perf_core
[ 55%] Built target opencv_flann
[ 55%] Built target opencv_test_flann
[ 59%] Built target opencv_test_imgproc
[ 62%] Built target opencv_perf_imgproc
[ 64%] Built target opencv_ml
[ 65%] Built target opencv_test_ml
[ 65%] Building CXX object modules/objdetect/CMakeFiles/opencv_objdetect.dir/src/detection_based_tracker.cpp.obj
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:175:14: error: 'thread' in namespace 'std' does not name a type
         std::thread second_workthread;
              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:176:14: error: 'mutex' in namespace 'std' does not name a type
         std::mutex mtx;
              ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:177:14: error: 'condition_variable' in namespace 'std' does not name a type
         std::condition_variable objectDetectorRun;
              ^~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:178:14: error: 'condition_variable' in namespace 'std' does not name a type
         std::condition_variable objectDetectorThreadStartStop;
              ^~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::setParameters(const cv::DetectionBasedTracker::Parameters&)':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:35: error: 'mutex' is not a member of 'std'
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                   ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:35: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:40: error: template argument 1 is invalid
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                        ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:51: error: 'mtx' was not declared in this scope
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                                   ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:42: warning: unused variable 'mtx_lock' [-Wunused-variable]
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                          ^~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::init()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:35: error: 'mutex' is not a member of 'std'
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                   ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:35: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:40: error: template argument 1 is invalid
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                        ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:51: error: 'mtx' was not declared in this scope
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                                   ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:164:13: error: 'objectDetectorThreadStartStop' was not declared in this scope
             objectDetectorThreadStartStop.notify_one();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:164:13: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
             objectDetectorThreadStartStop.notify_one();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             timeWhenDetectingThreadStartedWork
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:42: warning: unused variable 'mtx_lock' [-Wunused-variable]
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                          ^~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In destructor 'virtual cv::DetectionBasedTracker::SeparateDetectionWork::~SeparateDetectionWork()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:254:5: error: 'second_workthread' was not declared in this scope
     second_workthread.join();
     ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'bool cv::DetectionBasedTracker::SeparateDetectionWork::run()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:261:27: error: 'mutex' is not a member of 'std'
     std::unique_lock<std::mutex> mtx_lock(mtx);
                           ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:261:27: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:261:32: error: template argument 1 is invalid
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:261:43: error: 'mtx' was not declared in this scope
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                           ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:275:5: error: 'second_workthread' was not declared in this scope
     second_workthread = std::thread(workcycleObjectDetectorFunction, (void*)this); //TODO: add attributes?
     ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:275:30: error: 'thread' is not a member of 'std'
     second_workthread = std::thread(workcycleObjectDetectorFunction, (void*)this); //TODO: add attributes?
                              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:275:30: note: suggested alternative: 'tera'
     second_workthread = std::thread(workcycleObjectDetectorFunction, (void*)this); //TODO: add attributes?
                              ^~~~~~
                              tera
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:276:5: error: 'objectDetectorThreadStartStop' was not declared in this scope
     objectDetectorThreadStartStop.wait(mtx_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:276:5: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
     objectDetectorThreadStartStop.wait(mtx_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     timeWhenDetectingThreadStartedWork
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:317:27: error: 'mutex' is not a member of 'std'
     std::unique_lock<std::mutex> mtx_lock(mtx);
                           ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:317:27: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:317:32: error: template argument 1 is invalid
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:317:43: error: 'mtx' was not declared in this scope
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                           ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:323:9: error: 'objectDetectorThreadStartStop' was not declared in this scope
         objectDetectorThreadStartStop.notify_one();
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:323:9: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
         objectDetectorThreadStartStop.notify_one();
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         timeWhenDetectingThreadStartedWork
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:330:9: error: 'objectDetectorRun' was not declared in this scope
         objectDetectorRun.wait(mtx_lock);
         ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:340:14: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
     mtx_lock.unlock();
              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:357:22: error: request for member 'lock' in 'mtx_lock', which is of non-class type 'int'
             mtx_lock.lock();
                      ^~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:364:26: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
                 mtx_lock.unlock();
                          ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:372:13: error: 'objectDetectorRun' was not declared in this scope
             objectDetectorRun.wait(mtx_lock);
             ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:380:22: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
             mtx_lock.unlock();
                      ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:431:18: error: request for member 'lock' in 'mtx_lock', which is of non-class type 'int'
         mtx_lock.lock();
                  ^~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:447:18: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
         mtx_lock.unlock();
                  ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::stop()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:462:25: error: 'mutex' is not a member of 'std'
   std::unique_lock<std::mutex> mtx_lock(mtx);
                         ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:462:25: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:462:30: error: template argument 1 is invalid
   std::unique_lock<std::mutex> mtx_lock(mtx);
                              ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:462:41: error: 'mtx' was not declared in this scope
   std::unique_lock<std::mutex> mtx_lock(mtx);
                                         ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:468:18: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
         mtx_lock.unlock();
                  ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:479:5: error: 'objectDetectorRun' was not declared in this scope
     objectDetectorRun.notify_one();
     ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:480:5: error: 'objectDetectorThreadStartStop' was not declared in this scope
     objectDetectorThreadStartStop.wait(mtx_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:480:5: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
     objectDetectorThreadStartStop.wait(mtx_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     timeWhenDetectingThreadStartedWork
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:482:14: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
     mtx_lock.unlock();
              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::resetTracking()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:495:27: error: 'mutex' is not a member of 'std'
     std::unique_lock<std::mutex> mtx_lock(mtx);
                           ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:495:27: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:495:32: error: template argument 1 is invalid
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:495:43: error: 'mtx' was not declared in this scope
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                           ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:512:14: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
     mtx_lock.unlock();
              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'bool cv::DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread(const cv::Mat&, std::vector<cv::Rect_<int> >&)':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:533:27: error: 'mutex' is not a member of 'std'
     std::unique_lock<std::mutex> mtx_lock(mtx);
                           ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:533:27: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:533:32: error: template argument 1 is invalid
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:533:43: error: 'mtx' was not declared in this scope
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                           ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:566:9: error: 'objectDetectorRun' was not declared in this scope
         objectDetectorRun.notify_one();
         ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:573:14: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
     mtx_lock.unlock();
              ^~~~~~
mingw32-make[2]: *** [modulesobjdetectCMakeFilesopencv_objdetect.dirbuild.make:119: modules/objdetect/CMakeFiles/opencv_objdetect.dir/src/detection_based_tracker.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFilesMakefile2:2118: modules/objdetect/CMakeFiles/opencv_objdetect.dir/all] Error 2
mingw32-make: *** [Makefile:162: all] Error 2

And here is my Cmake File:

General configuration for OpenCV 3.3.1-dev =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2017-12-09T13:12:39Z
    Host:                        Windows 10.0.16299 AMD64
    CMake:                       3.10.0
    CMake generator:             MinGW Makefiles
    CMake build tool:            E:/Application/mingw-w64/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
      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:/Application/mingw-w64/mingw64/bin/g++.exe  (ver 7.2.0)
    C++ flags (Release):         -fsigned-char -mstackrealign -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 -Wno-implicit-fallthrough -Wno-strict-overflow -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 -mstackrealign -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 -Wno-implicit-fallthrough -Wno-strict-overflow -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:/Application/mingw-w64/mingw64/bin/gcc.exe
    C flags (Release):           -std=gnu++11 ${CMAKE_CXX_FLAGS}   -fsigned-char -mstackrealign -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 -Wno-implicit-fallthrough -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -std=gnu++11 ${CMAKE_CXX_FLAGS}   -fsigned-char -mstackrealign -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 -Wno-implicit-fallthrough -Wno-strict-overflow -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:
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann highgui imgcodecs imgproc ml objdetect photo 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
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.8)
    JPEG:                        build (ver 90)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.24)
    TIFF:                        build (ver 42 - 4.0.2)
    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.89.100)
      avformat:                  YES (ver 57.71.100)
      avutil:                    YES (ver 55.58.100)
      swscale:                   YES (ver 4.6.100)
      avresample:                YES (ver 3.5.0)
    GStreamer:                   NO
    DirectShow:                  YES

  Parallel framework:            none

  Trace:                         YES (built-in)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO

  NVIDIA CUDA:                   NO

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

  Python (for build):            NO

  Java:
    ant:                         NO
    JNI:                         E:/Application/Java/include E:/Application/Java/include/win32 E:/Application/Java/include
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:                        NO

  Install to:                    E:/Application/opencv/mingw-build/install
-----------------------------------------------------------------

@alalek

C flags (Release): -std=gnu++11 ${CMAKE_CXX_FLAGS}

Looks like compiler flags are misused:

  • c++ flag for C compilation
  • non-expanded variable

Clear CMake cache (clear build directory) and try again.

@tenderZeitGeist

Ah, clearly my fault there, I see. But after making sure, it was correct, regenerating the project with Cmake and another compiling attempt, I am still stuck at the detection_base_tracker.cpp.
What do you mean with «non-expanded variable»? Basically, I am leaving the most on default, except for precompiled headers and specify the compiler onto CXX_11, so I am quite a beginner, when it come to such things regarding C++, hence the question.

@alalek

${CMAKE_CXX_FLAGS} is non-expanded variable. It should not be there.

make VERBOSE=1 shows final compiler command-line options.

@tenderZeitGeist

Alright, so I redone it as you told me, but the error still occurs. Here is the log from the compilation attempt.

[ 65%] Building CXX object modules/objdetect/CMakeFiles/opencv_objdetect.dir/src/detection_based_tracker.cpp.obj
cd /d E:Applicationopencvmingw-buildmodulesobjdetect && E:Applicationmingw-w64mingw64bing++.exe -DCVAPI_EXPORTS -D_USE_MATH_DEFINES -D__OPENCV_BUILD=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS @CMakeFiles/opencv_objdetect.dir/includes_CXX.rsp -std=c++11 -fsigned-char -mstackrealign -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 -Wno-implicit-fallthrough -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -o CMakeFilesopencv_objdetect.dirsrcdetection_based_tracker.cpp.obj -c E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp

E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:175:14: error: 'thread' in namespace 'std' does not name a type
         std::thread second_workthread;
              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:176:14: error: 'mutex' in namespace 'std' does not name a type
         std::mutex mtx;
              ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:177:14: error: 'condition_variable' in namespace 'std' does not name a type
         std::condition_variable objectDetectorRun;
              ^~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:178:14: error: 'condition_variable' in namespace 'std' does not name a type
         std::condition_variable objectDetectorThreadStartStop;
              ^~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::setParameters(const cv::DetectionBasedTracker::Parameters&)':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:35: error: 'mutex' is not a member of 'std'
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                   ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:35: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:40: error: template argument 1 is invalid
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                        ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:51: error: 'mtx' was not declared in this scope
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                                   ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:143:42: warning: unused variable 'mtx_lock' [-Wunused-variable]
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                          ^~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::init()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:35: error: 'mutex' is not a member of 'std'
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                   ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:35: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:40: error: template argument 1 is invalid
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                        ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:51: error: 'mtx' was not declared in this scope
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                                   ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:164:13: error: 'objectDetectorThreadStartStop' was not declared in this scope
             objectDetectorThreadStartStop.notify_one();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:164:13: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
             objectDetectorThreadStartStop.notify_one();
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             timeWhenDetectingThreadStartedWork
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:156:42: warning: unused variable 'mtx_lock' [-Wunused-variable]
             std::unique_lock<std::mutex> mtx_lock(mtx);
                                          ^~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In destructor 'virtual cv::DetectionBasedTracker::SeparateDetectionWork::~SeparateDetectionWork()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:254:5: error: 'second_workthread' was not declared in this scope
     second_workthread.join();
     ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'bool cv::DetectionBasedTracker::SeparateDetectionWork::run()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:261:27: error: 'mutex' is not a member of 'std'
     std::unique_lock<std::mutex> mtx_lock(mtx);
                           ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:261:27: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:261:32: error: template argument 1 is invalid
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:261:43: error: 'mtx' was not declared in this scope
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                           ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:275:5: error: 'second_workthread' was not declared in this scope
     second_workthread = std::thread(workcycleObjectDetectorFunction, (void*)this); //TODO: add attributes?
     ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:275:30: error: 'thread' is not a member of 'std'
     second_workthread = std::thread(workcycleObjectDetectorFunction, (void*)this); //TODO: add attributes?
                              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:275:30: note: suggested alternative: 'tera'
     second_workthread = std::thread(workcycleObjectDetectorFunction, (void*)this); //TODO: add attributes?
                              ^~~~~~
                              tera
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:276:5: error: 'objectDetectorThreadStartStop' was not declared in this scope
     objectDetectorThreadStartStop.wait(mtx_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:276:5: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
     objectDetectorThreadStartStop.wait(mtx_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     timeWhenDetectingThreadStartedWork
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::workcycleObjectDetector()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:317:27: error: 'mutex' is not a member of 'std'
     std::unique_lock<std::mutex> mtx_lock(mtx);
                           ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:317:27: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:317:32: error: template argument 1 is invalid
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:317:43: error: 'mtx' was not declared in this scope
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                           ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:323:9: error: 'objectDetectorThreadStartStop' was not declared in this scope
         objectDetectorThreadStartStop.notify_one();
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:323:9: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
         objectDetectorThreadStartStop.notify_one();
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         timeWhenDetectingThreadStartedWork
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:330:9: error: 'objectDetectorRun' was not declared in this scope
         objectDetectorRun.wait(mtx_lock);
         ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:340:14: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
     mtx_lock.unlock();
              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:357:22: error: request for member 'lock' in 'mtx_lock', which is of non-class type 'int'
             mtx_lock.lock();
                      ^~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:364:26: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
                 mtx_lock.unlock();
                          ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:372:13: error: 'objectDetectorRun' was not declared in this scope
             objectDetectorRun.wait(mtx_lock);
             ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:380:22: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
             mtx_lock.unlock();
                      ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:431:18: error: request for member 'lock' in 'mtx_lock', which is of non-class type 'int'
         mtx_lock.lock();
                  ^~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:447:18: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
         mtx_lock.unlock();
                  ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::stop()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:462:25: error: 'mutex' is not a member of 'std'
   std::unique_lock<std::mutex> mtx_lock(mtx);
                         ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:462:25: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:462:30: error: template argument 1 is invalid
   std::unique_lock<std::mutex> mtx_lock(mtx);
                              ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:462:41: error: 'mtx' was not declared in this scope
   std::unique_lock<std::mutex> mtx_lock(mtx);
                                         ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:468:18: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
         mtx_lock.unlock();
                  ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:479:5: error: 'objectDetectorRun' was not declared in this scope
     objectDetectorRun.notify_one();
     ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:480:5: error: 'objectDetectorThreadStartStop' was not declared in this scope
     objectDetectorThreadStartStop.wait(mtx_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:480:5: note: suggested alternative: 'timeWhenDetectingThreadStartedWork'
     objectDetectorThreadStartStop.wait(mtx_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     timeWhenDetectingThreadStartedWork
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:482:14: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
     mtx_lock.unlock();
              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'void cv::DetectionBasedTracker::SeparateDetectionWork::resetTracking()':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:495:27: error: 'mutex' is not a member of 'std'
     std::unique_lock<std::mutex> mtx_lock(mtx);
                           ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:495:27: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:495:32: error: template argument 1 is invalid
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:495:43: error: 'mtx' was not declared in this scope
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                           ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:512:14: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
     mtx_lock.unlock();
              ^~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp: In member function 'bool cv::DetectionBasedTracker::SeparateDetectionWork::communicateWithDetectingThread(const cv::Mat&, std::vector<cv::Rect_<int> >&)':
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:533:27: error: 'mutex' is not a member of 'std'
     std::unique_lock<std::mutex> mtx_lock(mtx);
                           ^~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:533:27: error: 'mutex' is not a member of 'std'
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:533:32: error: template argument 1 is invalid
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                ^
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:533:43: error: 'mtx' was not declared in this scope
     std::unique_lock<std::mutex> mtx_lock(mtx);
                                           ^~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:566:9: error: 'objectDetectorRun' was not declared in this scope
         objectDetectorRun.notify_one();
         ^~~~~~~~~~~~~~~~~
E:Applicationopencvopencv_sourcemodulesobjdetectsrcdetection_based_tracker.cpp:573:14: error: request for member 'unlock' in 'mtx_lock', which is of non-class type 'int'
     mtx_lock.unlock();
              ^~~~~~
mingw32-make[2]: *** [modulesobjdetectCMakeFilesopencv_objdetect.dirbuild.make:119: modules/objdetect/CMakeFiles/opencv_objdetect.dir/src/detection_based_tracker.cpp.obj] Error 1
mingw32-make[2]: Leaving directory 'E:/Application/opencv/mingw-build'
mingw32-make[1]: *** [CMakeFilesMakefile2:2118: modules/objdetect/CMakeFiles/opencv_objdetect.dir/all] Error 2
mingw32-make[1]: Leaving directory 'E:/Application/opencv/mingw-build'
mingw32-make: *** [Makefile:162: all] Error 2

@alalek

Try to run your MinGW compiler with this code:

#include <thread>
#include <mutex>
#include <condition_variable>

std::thread second_workthread;
std::mutex mtx;
std::condition_variable objectDetectorRun;

@viraltailor1

I have a same issue please provide me some solution……

@tenderZeitGeist

Alright, I just wanted to leave a note, that the problem got solved and I was able to successfully compile the source files into binaries, but I haven’t tried to use them. Either way, this issue can be closed.
However, if you want to here the solution to it, I will try my best to explain this issue and how to avoid it in the first place.

When I installed MinGW for the first time, I selected under «Threads» the option «win32», as I thought this was the obvious choice. But to use OpenCV under Windows, you need to select «posix» instead of «win32» threads. This came to my mind while browsing through this thread. In conclusion, if you are not able to compile the source files at this very class/file (detection_based_tracker.cpp.obj), it is very likely due to this.

So, if you are intending of using your own compiled version of OpenCV, I suggest you this:
1.) Download the compiler.
2.) Uninstall your current MinGW compiler.
3.) Reinstall MinGW again.
4.) Understand the option «Threads», chose «posix».

I understand, there are different options and ways, this is sole the way, I handled it. And I hope, it might help one or another C++ or OpenCV rookie.

Cheers.

humanbeingZ, A-Hopkins, curiosity654, Mymiku, windowsair, yanite, gabrossmann, alalek, WilliamBehrens, enzo-simone, and 14 more reacted with thumbs up emoji
humanbeingZ, stevensgeek41, LeDuySon, WenyinWei, and NovGee reacted with hooray emoji

@alitokur

This comment has been minimized.

@huanghaozi

huh sorry sir, i didnt get it. how can i install mingw compiler from the zip?

seems to be….just unzip it….And add «bin» directory to the environment variable…

CMakelist.txt:

set(CMAKE_CXX_STANDARD 23)

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )

add_executable(Facial_Recognition main.cpp)

target_link_libraries( Facial_Recognition ${OpenCV_LIBS} )

Main:

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

using namespace cv;

int main() {
    Mat image;
    image = imread("C:/Users/user/OneDrive - De Montfort University/Work/headshot.jpg");
    namedWindow("Display image", WINDOW_AUTOSIZE);
    imshow("Display Image", image);
    waitKey(0);

    return 0;

The errors I get when trying to use the above code:

[ 50%] Building CXX object
CMakeFiles/Facial_Recognition.dir/main.cpp.obj In file included from
C:/opencv/build/include/opencv2/core.hpp:3307:0,
from C:/opencv/build/include/opencv2/opencv.hpp:52,
from C:UsersuserDesktopFacial Recognitionmain.cpp:2:
C:/opencv/build/include/opencv2/core/utility.hpp:718:14: error:
‘recursive_mutex’ in namespace ‘std’ does not name a type typedef
std::recursive_mutex Mutex;
^~~~~~~~~~~~~~~ C:/opencv/build/include/opencv2/core/utility.hpp:719:25: error:
‘Mutex’ is not a member of ‘cv’ typedef std::lock_guard<cv::Mutex>
AutoLock;
^~ C:/opencv/build/include/opencv2/core/utility.hpp:719:34: error:
template argument 1 is invalid typedef std::lock_guard<cv::Mutex>
AutoLock;
^ In file included from C:/opencv/build/include/opencv2/flann/kdtree_index.h:44:0,
from C:/opencv/build/include/opencv2/flann/all_indices.h:38,
from C:/opencv/build/include/opencv2/flann/flann_base.hpp:44,
from C:/opencv/build/include/opencv2/flann.hpp:48,
from C:/opencv/build/include/opencv2/opencv.hpp:65,
from C:UsersuserDesktopFacial Recognitionmain.cpp:2: C:/opencv/build/include/opencv2/flann/heap.h:
In static member function ‘static cv::Ptrcvflann::Heap<T >
cvflann::Heap::getPooledInstance(const HashableT&, int, int)’:
C:/opencv/build/include/opencv2/flann/heap.h:191:20: error: ‘Mutex’ in
namespace ‘cv’ does not name a type
static cv::Mutex mutex;
^~~~~ C:/opencv/build/include/opencv2/flann/heap.h:192:33: error: ‘mutex’
was not declared in this scope
const cv::AutoLock lock(mutex);
^~~~~ mingw32-make.exe[3]: *** [CMakeFiles/Facial_Recognition.dir/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Facial_Recognition.dir/all] Error
2 mingw32-make.exe[1]: *** [CMakeFiles/Facial_Recognition.dir/rule]
Error 2 mingw32-make.exe: *** [Facial_Recognition] Error 2
CMakeFilesFacial_Recognition.dirbuild.make:71: recipe for target
‘CMakeFiles/Facial_Recognition.dir/main.cpp.obj’ failed
CMakeFilesMakefile2:81: recipe for target
‘CMakeFiles/Facial_Recognition.dir/all’ failed
CMakeFilesMakefile2:88: recipe for target
‘CMakeFiles/Facial_Recognition.dir/rule’ failed Makefile:123: recipe
for target ‘Facial_Recognition’ failed

  • Summary

  • Files

  • Reviews

  • Support

  • Mailing Lists

  • Tickets ▾

    • External Testsuite Failures
    • Bugs
    • Support Requests
    • Patches (Obsolete, use public Mailing List)
    • Feature Requests
  • News

  • Discussion

  • Donate

  • Code

  • Git ▾

    • web
    • ironcrate
    • mingw-w64
    • portablexdr
  • Wiki2

Menu

Failed to find std::recursive_mutex while building opencv-4.1.1 on windows


Created:

2019-08-18

Updated:

2019-08-20

  • Karl Liu

    At first, while building openerx required by opencv, it reports that std::mutex couldn’t be found. For erx extension is useless to me, I disabled it. However, multithread is also required by opencv_core which shouldn’t be disabled.

    Operating System: Windows 10 ver. 1903
    MinGW-w64: x86_64-win32-seh-rev0 8.1.0
    OpenCV: 4.1.1
    CMake: 3.15.2

    Error Message:

    [ 29%] Building CXX object modules/world/CMakeFiles/opencv_world.dir/__/core/src/algorithm.cpp.obj
    In file included from D:opencvopencv-4.1.1modulescoresrcprecomp.hpp:49,
                     from D:opencvopencv-4.1.1modulescoresrcalgorithm.cpp:43:
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:701:14: error: 'recursive_mutex' in namespace 'std' does not name a type
     typedef std::recursive_mutex Mutex;
                  ^~~~~~~~~~~~~~~
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:701:9: note: 'std::recursive_mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:63:1:
    +#include <mutex>
     #endif
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:701:9:
     typedef std::recursive_mutex Mutex;
             ^~~
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:702:29: error: 'Mutex' is not a member of 'cv'
     typedef std::lock_guard<cv::Mutex> AutoLock;
                                 ^~~~~
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:702:29: note: suggested alternative: 'Matx'
     typedef std::lock_guard<cv::Mutex> AutoLock;
                                 ^~~~~
                                 Matx
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:702:29: error: 'Mutex' is not a member of 'cv'
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:702:29: note: suggested alternative: 'Matx'
     typedef std::lock_guard<cv::Mutex> AutoLock;
                                 ^~~~~
                                 Matx
    D:/opencv/opencv-4.1.1/modules/core/include/opencv2/core/utility.hpp:702:34: error: template argument 1 is invalid
     typedef std::lock_guard<cv::Mutex> AutoLock;
                                      ^
    In file included from D:opencvopencv-4.1.1modulescoresrcalgorithm.cpp:43:
    D:opencvopencv-4.1.1modulescoresrcprecomp.hpp:365:5: error: 'Mutex' in namespace 'cv' does not name a type
     cv::Mutex& getInitializationMutex();
         ^~~~~
    D:opencvopencv-4.1.1modulescoresrcprecomp.hpp:365:1: note: suggested alternative: 'Matx'
     cv::Mutex& getInitializationMutex();
     ^~
     Matx
    make[2]: *** [modules/world/CMakeFiles/opencv_world.dir/__/core/src/algorithm.cpp.obj] Error 1
    make[1]: *** [modules/world/CMakeFiles/opencv_world.dir/all] Error 2
    make: *** [all] Error 2
    

    Thanks.

     

    Last edit: Karl Liu 2019-08-18

  • Karl Liu

    Trying to locate the problem, I wrote a tiny program:

    #include <mutex>
    
    int main() {
        std::mutex mtx;
        return 0;
    }
    

    And when attempting to compile it, the g++ reports:

    PS D:> g++ .try-mutex.cpp
    .try-mutex.cpp: In function 'int main()':
    .try-mutex.cpp:5:10: error: 'mutex' is not a member of 'std'
         std::mutex mtx;
              ^~~~~
    .try-mutex.cpp:5:10: note: 'std::mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
    .try-mutex.cpp:3:1:
    +#include <mutex>
    
    .try-mutex.cpp:5:10:
         std::mutex mtx;
              ^~~~~
    

    so maybe my installation of mingw is not correct?

     

    Last edit: Karl Liu 2019-08-19

  • Zufu Liu

    Please use x86_64-posix-seh or i686-posix-dwarf, the win32 thread model doesn’t support C++11 threading features.

    • Karl Liu

      It works! Thanks a lot.

      BTW, does it means that MinGW implements the POSIX interface in Windows OS?

    • Karl Liu

      It works! Thanks a lot.

      BTW, does it means that MinGW implements the POSIX interface in Windows OS?

      • Zufu Liu

        Only subsets, doesn’t provide every thing provided by glibc.

  • E.Naumovich


Log in to post a comment.

Having resolved the problem in my previous question

I installed caffe following the guide and it works fine until I get to the make runtest step.

At this point it throws the

[ RUN      ] ImageDataLayerTest/0.TestResize
*** Aborted at 1477424981 (unix time) try "date -d @1477424981" if you are using GNU date ***
PC: @     0x7efe83917d84 __GI___pthread_mutex_lock
*** SIGSEGV (@0x3038) received by PID 8354 (TID 0x7efe8c938180) from PID 12344; stack trace: ***
    @     0x7efe8391f3d0 (unknown)
    @     0x7efe83917d84 __GI___pthread_mutex_lock
    @     0x7efe61f51008 (unknown)
    @     0x7efe62005671 (unknown)
    @     0x7efe620057e5 (unknown)
    @     0x7efe61f56cb4 (unknown)
    @     0x7efe61f584e7 (unknown)
    @     0x7efe61f2bc66 (unknown)
    @     0x7efe61e2af3d (unknown)
    @     0x7efe61e2aed8 (unknown)
    @     0x7efe627b3d30 (unknown)
    @     0x7efe627b4233 clGetPlatformIDs
    @     0x7efe86f78ad5 (anonymous namespace)::opencl_fn3<>::switch_fn()
    @     0x7efe8702786a cv::ocl::haveOpenCL()
    @     0x7efe87036c08 cv::ocl::useOpenCL()
    @     0x7efe8561af7c cv::resize()
    @     0x7efe8431dbe7 caffe::ReadImageToCVMat()
    @     0x7efe842dbe7e caffe::ImageDataLayer<>::DataLayerSetUp()
    @     0x7efe8422e1e3 caffe::BasePrefetchingDataLayer<>::LayerSetUp()
    @           0x48c95f caffe::Layer<>::SetUp()
    @           0x4a8597 caffe::ImageDataLayerTest_TestResize_Test<>::TestBody()
    @           0x8e0693 testing::internal::HandleExceptionsInMethodIfSupported<>()
    @           0x8d9caa testing::Test::Run()
    @           0x8d9df8 testing::TestInfo::Run()
    @           0x8d9ed5 testing::TestCase::Run()
    @           0x8db1af testing::internal::UnitTestImpl::RunAllTests()
    @           0x8db4d3 testing::UnitTest::Run()
    @           0x466e7d main
    @     0x7efe83565830 __libc_start_main
    @           0x46e489 _start
    @                0x0 (unknown)

error.

here is some relevant information:
nvcc version:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Tue_Aug_11_14:27:32_CDT_2015
Cuda compilation tools, release 7.5, V7.5.17

graphics card:

$ sudo lshw -c video
  *-display               
       description: VGA compatible controller
       product: GK107GLM [Quadro K1000M]
       vendor: NVIDIA Corporation
       physical id: 0
       bus info: pci@0000:01:00.0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
       configuration: driver=nvidia latency=0
       resources: irq:35 memory:d8000000-d8ffffff memory:c0000000-cfffffff memory:d0000000-d1ffffff ioport:4000(size=128) memory:d9080000-d90fffff

my graphics driver is

nvidia-opencl-icd-361-updates

I googled for the problem but could only find a suggestion that it may be a problem with opencv (I use opencv-3.1.0 ).

  • Remove From My Forums
  • Вопрос

  • Hi, gentlemen from Microsoft, I am developing an application on the Microsoft visual studio 2017 platform with the Opencv libraries that compile it with cmake, the application that develops in c ++ compiles and runs perfectly, but when working in a Windows form application CLR, it gives me two errors, which I reveal below.

    Directorio de inclusiones adicionales C:UsersLaboratorioDocumentsopencv3.0buildinstallinclude % funciona correcto% Directorio de bibliotecas
    adicionales: C:UsersLaboratorioDocumentsopencv3.0buildinstallx64vc15lib %funciona corecto% EL ERROR SE PRODUCE AL DEPURAR EL FORMULARIO CON LAS DIRECTIVAS: #pragma once #include <opencv2/opencv.hpp> //directiva opencv #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/objdetect/objdetect.hpp> //#include<opencv2/face.hpp> #include <opencv/cv.h> ////importante #include <opencv2/ml.hpp> namespace
    SOFTWARENUEVO { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace System::Threading; using
    namespace cv; using namespace std; /// <summary> /// Resumen de MyForm5 /// </summary> public ref class MyForm5 : public System::Windows::Forms::Form {

    I WOULD LIKE YOUR GUIDANCE to solve the problem that I am trying to solve.
    Error messages

    Severity Code Description Project File Line State deleted Tool

    Error (active) E0035 directive #error: <thread> is not supported when compiling with / clr or / clr: pure.SOFTWARENUEVO c: Program Files (x86) Microsoft Visual Studio 2017 Community VC Tools MSVC 14.13.26128 include thread 8 Visual C ++ IntelliSense

    Gravedad           Código  Descripción        Proyecto            
    Archivo Línea     Estado suprimido            Herramienta

    Error C1189 #error: <mutex> no es compatible cuando se compila con / clr o / clr: pure.SOFTWARENUEVO c: archivos de programa (x86) microsoft
    visual studio 2017 community vc tools msvc 14.13.26128 include mutex 8 CL

    • Изменено

      23 мая 2018 г. 6:04

    • Перемещено
      Baron Bi
      28 мая 2018 г. 7:47
      Not an English case

Содержание

  1. windows: OpenCV 4.3.0 build failing on generating vs_version.rc using mingw-w64 #16990
  2. Comments
  3. Footer
  4. opencv 4.3 compiling problems on windows #17065
  5. Comments
  6. Opencv mingw error build
  7. Comments
  8. OpenCV C++ installation on Windows with MinGW
  9. Prerequisites
  10. Step 1
  11. Step 2
  12. Step 3
  13. Step 4
  14. Step 5
  15. Как исправить ошибку при компиляции проекта с OpenCv в Сlion?

windows: OpenCV 4.3.0 build failing on generating vs_version.rc using mingw-w64 #16990

System information (version)
  • OpenCV => 4.3.0
  • Operating System / Platform => Windows 64-bit
  • Compiler => mingw-w64 v7.3.0
Detailed description

Our current build script fails on our Appveyor CI build when we update to OpenCV 4.3.0. Not sure about the origin of this issue. Thanks for any help.

Steps to reproduce

The text was updated successfully, but these errors were encountered:

Please add full log including cmake step.

Please dump compiler command line options: make VERBOSE=1

Allocator metrics storage type: ‘long long’

Perhaps this one is related (see #16786). Try to pass:

Hi @alalek adding the -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int64_t option to CMAKE allows the build to complete.

If this is covered by #16786 then should I close this issue?

Feel free to propose patch with default value for mingw here (to 3.4 branch).

CMake generator: MinGW Makefiles

Also it might that this CMake generator doesn’t handle spaces in definitions well (this generator is used rarely with CMake).
Consider using «ninja» if it is supported by AppVeyor environment.

OK, sounds good. I will look into if there is a coherent patch I could submit, or possibly switching to ninja.

Now closing this issue, thanks very much @alalek and @dkurt for quick response.

Hi @alalek adding the -DOPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int64_t option to CMAKE allows the build to complete.

If this is covered by #16786 then should I close this issue?

@alalek when in the cmake-gui , to add the entry, which type should i select (BOOL or STRING ). And should i check the value box. Thanks

Hi, @alalek , i used mingw32-make to build opencv3.4 and contrib and have an error like oben:gcc error: No such file or directory and then i have added OPENCV_ALLOCATOR_STATS_COUNTER_TYPE = int64_t in cmake:

and have another problem:
Could you tell me what happends hier and how to solve this problem? Thanks a lot.

Hi, @yiyayiyau i am getting the same errors. I could not find the solution. Can you share if you found the solution? Thanks a lot.

© 2023 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

opencv 4.3 compiling problems on windows #17065

System information (version)

OpenCV => 4.3
Operating system : windows 10 64 bit
Compiler : Mingw-64 v8.1.0

Detailed description

Getting error related to rc object

Steps to reproduce
  • install Cmake 3.8.2 or latest ( i tried latest and 3.8.2 as some users on forums said that they downgraded to 3.8.2 and then rc.object error resolved ) but not worked for me
  • download and install mingw-64 to C:mingw-w64 : https://netix.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe
  • set system path to : C:mingw-w64x86_64-8.1.0-posix-seh-rt_v6-rev0mingw64bin
  • open CMD
  • cd C:opencvsource
  • git clone https://github.com/opencv/opencv.git
  • git clone https://github.com/opencv/opencv_contrib.git
  • open cmake gui
  • set source and build directories : C:opencvbuild
  • click configure
  • search java , uncheck BUILD_JAVA
  • search python uncheck BUILD_PYTHON
  • search openexr , uncheck BUILD_OPENEXR
  • search WITH_IPP , uncheck WITH_IPP
  • search ENABLE_PRECOMPILED_HEADERS , uncheck it
  • search WITH_OPENGL , check it
  • search free and check OPENCV_ENABLE_NONFREE
  • set OPENCV_EXTRA_MODULES_PATH to C:opencvsourceopencv-contribmodules

+click configure , wait till its completed
+click generate

  • open CMD with admin rights
  • cd C:opencvbuild
  • mingw32-make -j 8
  • you will see error ?

Cmake config output

The text was updated successfully, but these errors were encountered:

Источник

Opencv mingw error build

First time here? Check out the FAQ!

I am trying to compile OpenCV 3.4.1 with CMake 3.11.3 using Qt5.11 MinGW on windows 10 but it gives me error when i try to generate in Cmake. I would like to use openCV libraries in Qt 5.11.

I followed the following steps mentioned here. Following is the debug output:

  • mingw version 5.3.0 — that is quite old. (also, 32bits,hmmm) . maybe getting latest mingw64 is a better idea, than using that.
  • please clarify: do you want to build the opencv highgui qt extensions , or do you want to build programs with your own, qt based ui later ? (this is kind of XOR, you have to make a decision)
  • ENABLE_PRECOMPILED_HEADERS=OFF

Hi Berak, Thanks for the reply. I would like to build programs on my own using qt based ui at a later stage. I will try to update mingw.

in that case try :

maybe that cures it already (highgui)

try that, and report back, please.

Hi Berak, Yesterday I tried multiple times to compile but didnt succeed with your suggested methods. I then tried to put BUILD_opencv_highgui=OFF , BUILD_PROTOBUF=OFF, WITH_PROTOBUF=OFF and I was then able to generate from cmake but in command prompt when I do: mingw32-make install I get following errors:

modulesvideoioCMakeFilesopencv_videoio.dirbuild.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 CMakeFilesMakefile2:2194: 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

I don’t know how should I proceed with compilation. Do you have any other suggestions? I didn’t tried with mingw64 as their website is down for maintenance since yesterday so I couldn’t donwload it. I will try to compile with lower version of opencv now. I will keep you updated.

Источник

OpenCV C++ installation on Windows with MinGW

These days getting OpenCV running inside python is quite easy given conda does handle the installing the binaries and bringing the opencv python bindings inside python path.

However getting the same to run in C++ , is a different story. C++ is all about bringing in the right interface (hpp/header files) and binaries (so/dll) in the context of the program being compiled by the “g++” compiler. I will show you how I was able to set my system up for the same. Most tutorials out there will consider using an IDE like Eclipse or Netbeans. For bringing in “g++” (GNU C++ compiler) , we will use MinGW64. Remember we must use the 64bit variant since Mingw32 does not supports posix threads properly in windows. The ming64 binaries are built with a posix implementation that gives native posix but when compiled on windows will be slower compared to something built on windows native API (win32)

Prerequisites

  1. Windows (10/8/7) system
  2. Mingw-w64 , you can download from here
  3. OpenCv 3+ , official github repo
  4. Cmake , download from here
  5. Editor and terminal, do not care what you use. You can use notepad 😥 if you wish.

Step 1

Download the OpenCV source from their official git repository. You can choose to download any one of them. In my case I went for this one

Step 2

Setup Mingw-w64. In case you had trouble finding the link. Look here . Go for the link that says Online Installer for MinGW-GW64. Direct link , may break in future.

  1. Install MinGW-GW64 with the following setting

Make sure posix is selected. Otherwise the OpenCV installation will fail with unable to find mutex error. Which is part of pthreads library and specs. Architecture can be x86(32/64 bit machin) or x86_64(64bit machine) based on your working system.

2. Click next configure path of installation and let the binaries install.

3. After installation make sure to include MinGW bin folder in your path. It should be inside “..basePath/x86_64–8.1.0-posix***/mingw64/bin”

After this just test the installation by opening a terminal and type command “g++ — version”. If it says command not found. It could not get the path ,path was not set right, restart terminal or the machine. It should work! Google for the same !

Step 3

Once done install Cmake. Open Cmake and do the following

  1. Choose a source code path and a binaries path. Make sure they are separate.

2. Once done click on configure.A dialogue box will appear select MinGW Makefiles. This will make sure that the OpenCV new makefiles are compatible to mingw.

3. Click Finish. Let it generate some stuff. At this stage you should have some list of options to tick on. I did not needed any special attention to any of those options. So go on and click on Generate. Match the output from below, it should say “Configuration done” and “Generating done”

Step 4

Remember we chose a binaries folder, keep that in mind. Now navigate to that folder and open a terminal. In my case the folder I will have to navigate is.
“ C:UsersAsusDesktopopencv”. Open a terminal in this folder. I use git-bash and you can use too. hit command “mingw32-make install” and pray that it builds hopefully. Because if it does my tutorial was successful.

After it’s done it should look like this. Also C++ compilation process takes a lot of time, LOT OF TIME . There are conference discussion on the same !! So you understand how serious is this problem.

At this point a new folder install will be created in your targeted build folder. We are concerned with the contents of this folder. So let’s do one thing. Lets move our build folder to “C:” drive root path that contains the install folder also. Now we add the binary path. Refer from the above image. In the environment variable there is a second path that points at the bin folder add that to environment variable also. Path “ C:opencvinstallx64mingwbin” must be included in environment variable. This was in our case. These paths are IMPORTANT . 😧 Make sure it is there. The bin folder consist of all the various compiled binaries that are required for our OpenCV C++ compiled application. So you can choose to ship your application but then you will require the dll inside the bin to be shipped with your application also. Also since they are dll you cannot statically link them. So “-static” does not works. At least I could not get it done.

Step 5

Write a program

Now once you have the code copied. It’s time to test the installation. Remember to change the image location to your target image. Make sure you do that otherwise empty Mat will be created.

Double check that the include ,lib and bin folder of the install folder are targeted by your g++ compilation command.

If your command worked with no error. If there are linker errors then would advice to check whether linked dll are existing in the folder included by the command.

So hopefully you got a similar out put of size of the image currently being used.

Hope this tutorial helps you start your journey into the rabbit hole of C++ and Computer Vision. For more such content to follow this blog and if you found this helpful maybe a few claps. 😄 ….

Hopefully in the next version we will try to support cuda for Opencv DNN module.

Источник

Как исправить ошибку при компиляции проекта с OpenCv в Сlion?

Linking CXX executable OpenCv_Test_1.exe
CMakeFilesOpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `main’:
C:/Users/Peter Zaydel/AndroidStudioProjects/OpenCv_Test_1/main.cpp:12: undefined reference to `cv::imread(cv::String const&, int)’
C:/Users/Peter Zaydel/AndroidStudioProjects/OpenCv_Test_1/main.cpp:20: undefined reference to `cv::namedWindow(cv::String const&, int)’
C:/Users/Peter Zaydel/AndroidStudioProjects/OpenCv_Test_1/main.cpp:21: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)’
C:/Users/Peter Zaydel/AndroidStudioProjects/OpenCv_Test_1/main.cpp:23: undefined reference to `cv::waitKey(int)’
CMakeFilesOpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv6StringC1EPKc’:
C:/OpenCV/opencv/build/include/opencv2/core/cvstd.hpp:618: undefined reference to `cv::String::allocate(unsigned int)’
CMakeFilesOpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv6StringD1Ev’:
C:/OpenCV/opencv/build/include/opencv2/core/cvstd.hpp:660: undefined reference to `cv::String::deallocate()’
CMakeFilesOpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv3MatD1Ev’:
C:/OpenCV/opencv/build/include/opencv2/core/mat.inl.hpp:556: undefined reference to `cv::fastFree(void*)’
CMakeFilesOpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv3MataSERKS0_’:
C:/OpenCV/opencv/build/include/opencv2/core/mat.inl.hpp:577: undefined reference to `cv::Mat::copySize(cv::Mat const&)’
CMakeFilesOpenCv_Test_1.dir/objects.a(main.cpp.obj): In function `ZN2cv3Mat7releaseEv’:
C:/OpenCV/opencv/build/include/opencv2/core/mat.inl.hpp:667: undefined reference to `cv::Mat::deallocate()’
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [OpenCv_Test_1.exe] Error 1
CMakeFilesOpenCv_Test_1.dirbuild.make:87: recipe for target ‘OpenCv_Test_1.exe’ failed
CMakeFilesMakefile2:59: recipe for target ‘CMakeFiles/OpenCv_Test_1.dir/all’ failed
mingw32-make.exe[2]: *** [CMakeFiles/OpenCv_Test_1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/OpenCv_Test_1.dir/rule] Error 2
CMakeFilesMakefile2:71: recipe for target ‘CMakeFiles/OpenCv_Test_1.dir/rule’ failed
Makefile:108: recipe for target ‘OpenCv_Test_1’ failed
mingw32-make.exe: *** [OpenCv_Test_1] Error 2

Советы из схожей проблемы на SO не помогают.

Источник

Я пытаюсь настроить OpenCV, какой-то базовый код, чтобы просто начать с него и посмотреть, что я могу сделать. Но каждый раз, когда я пытаюсь скомпилировать приложение, я получаю сообщение об ошибке 'Mutex' is not a member of 'cv'. Пробовал некоторые другие решения, например. это

Моя среда — это VS Code с c_cpp_properties.json, установленным следующим образом:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}",
                "C:\MinGW\lib\gcc\mingw32\8.2.0\include\c++",
                "C:\MinGW\lib\opencv\build\include"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.17763.0",
            "compilerPath": "C:\MinGW\posix\mingw64\bin\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
            "browse": {
                "path": [
                    "${workspaceFolder}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ],
    "version": 4
}

Пробовал несколько переустановок g++ и все такое minGW, ничего не работает.

Это мой код main.cpp:

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp> 
#include <string> 
#include <iostream> 

using namespace cv; 
using namespace std; 

int main() 
{ 
    const string file_name = "sunflower.jpg"; 
    Mat img = imread(file_name); 
    if( !img.data ) 
    { 
        cout << "Nie odnalezionu pliku " << file_name; 
        return -1; 
    } 
    const string window_name = "OpenCV_1"; 
    namedWindow(window_name, WINDOW_AUTOSIZE); 
    imshow(window_name, img); 
    waitKey(0); 
    return 0; 
}

Консольный вывод

 Executing task: g++ -g -o bin/debug.exe src/main.cpp -IC:MinGWlibopencvbuildinclude -LC:MinGWlibopencvbuildx64vc15bin -llibopencv_highgui242 -llibopencv_features2d242 -llibopencv_flann242 -llibopencv_objdetect242 -llibopencv_video242 -llibopencv_calib3d242 -llibopencv_contrib242 -llibopencv_imgproc242 -llibopencv_core242 -llibopencv_ml242 -llibopencv_legacy242 -llibopencv_nonfree242 -llibopencv_photo242 -llibopencv_stitching242 -llibopencv_videostab242 <

In file included from C:MinGWlibopencvbuildinclude/opencv2/core.hpp:3290,
                 from C:MinGWlibopencvbuildinclude/opencv2/highgui.hpp:46,
                 from C:MinGWlibopencvbuildinclude/opencv2/highgui/highgui.hpp:48,
                 from src/main.cpp:1:
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:697:14: error: 'recursive_mutex' in namespace 'std' does not name a type
 typedef std::recursive_mutex Mutex;
              ^~~~~~~~~~~~~~~
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:697:9: note: 'std::recursive_mutex' is defined in header '<mutex>'; did you forget to '#include <mutex>'?
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:60:1:
+#include <mutex>

C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:697:9:
 typedef std::recursive_mutex Mutex;
         ^~~
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:29: error: 'Mutex' is not a member of 'cv'
 typedef std::lock_guard<cv::Mutex> AutoLock;
                             ^~~~~
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:29: note: suggested alternative: 'Matx'
 typedef std::lock_guard<cv::Mutex> AutoLock;
                             ^~~~~
                             Matx
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:29: error: 'Mutex' is not a member of 'cv'
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:29: note: suggested alternative: 'Matx'
 typedef std::lock_guard<cv::Mutex> AutoLock;
                             ^~~~~
                             Matx
C:MinGWlibopencvbuildinclude/opencv2/core/utility.hpp:698:34: error: template argument 1 is invalid
 typedef std::lock_guard<cv::Mutex> AutoLock;
                                  ^
The terminal process terminated with exit code: 1

Мне нужно решение для настройки g++ для компиляции приложения. Или сделать что-то, о чем я еще не знаю.

1 ответ

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Opencv error cannot load info library for opencv
  • Opencv error 215 assertion failed
  • Opencl kernel build error 11
  • Opencl error 1001
  • Opencl dll error 126

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии