0

I am trying to compile OpenCV3 and put it into Qt project because Qt officially provides MinGW Version, so I didn't use MinGW-w64.

I enabled ENABLE_CXX11 and disabled ENABLE_PRECOMPILED_HEADERS in CMake.

Now the problem is MinGW does not contain std::thread.

I know the mingw-std-threads lib can fix it. but I don't want to modify OpenCV source code. Is there any other way to adding c++ thread feature to MinGW? or tell OpenCV using pthread by CMake?

BTW. I don't want use Qt's MinGW because I think using official MinGW to compile the lib shall be used in any version of Qt.

Update:

In OpenCV detection_based_tracker.cpp, there is a CV_CXX11 Marco choice to the using std thread or the pthread. But I didn't see anywhere define CV_CXX11.

Is part of detection_based_tracker.cpp code:

#ifdef CV_CXX11
#define USE_STD_THREADS
#endif

#ifdef USE_STD_THREADS
#include <thread>
#include <mutex>
#include <condition_variable>
#else //USE_STD_THREADS
#include <pthread.h>
#endif //USE_STD_THREADS

My environment:

windows 7 64bit
cmake-3.10.1-win64-x64
opencv-3.4.0
gcc 6.3

What I tried:

  1. install CMake and MinGW
  2. disable ENABLE_PRECOMPILED_HEADERS in CMake-gui
  3. comment #define USE_STD_THREADS in detection_based_tracker.cpp line 48
  4. configure and generate Makefile
  5. Run mingw32-make

it's successfully compiled, but I have to modify OpenCV source code.

JustWe
  • 4,250
  • 3
  • 39
  • 90

1 Answers1

0

If you use the right version of MinGW, namely MinGW-w64, most toolchains builds have the modern threading features available.

You can e.g. use the installer or install it through MSYS2.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Thanks, I tried MinGW-w64 and it works, But I need to add the OpenCV into official Qt which bases on MinGW32, So I have to use the MinGW32. – JustWe Jan 10 '18 at 07:21
  • Recent Official Qt builds should be using a MinGW-w64 based distribution of GCC. I'm not entirely sure they properly enable c++ threads though. You can check by running "gcc -v" and checking if the threading model is "posix". This should mean, on GCC versions >= 4.9 that C++11 threads are available. – rubenvb Jan 10 '18 at 08:54