3

This post contains all the problems I (and other users) had while building the library from sources. As there is no tutorial, I decided to create this sort of FAQ post to put all the solutions together. Hope it will help!

Configuration:
OpenCV 3.2.0
MinGW-w64 x86_64-6.1.0-win32-seh-rt_v5-rev0

You are welcome to add more information in the answers, as it is more handy to have everything in one place.

Alex
  • 1,077
  • 9
  • 24
  • WOW wonderful!! Do you know how to use `dlib` with OpenCV in python for Windows environment? – Jeru Luke Jan 29 '17 at 07:57
  • This could be fine for StackOver Documentation, but it not a valid question. – usr1234567 Jan 29 '17 at 13:21
  • @usr1234567 it was intended to be a Q&A question. I think it needs some better solutions for errors 3 and 4 to be a doc – Alex Jan 30 '17 at 02:08
  • @JeruLuke, unfortunatelly, I don't – Alex Jan 30 '17 at 02:09
  • @Alex Perhaps you can document this answer in the **Documentation** section. Such content must not go to waste – Jeru Luke Jan 30 '17 at 02:22
  • 1
    @JeruLuke, as far as I know, the question is just going to be closed, not deleted. I will probably move it to the Documentation as soon as the solutions it offers get good enough. Docs are for docs :) – Alex Jan 30 '17 at 06:16

1 Answers1

6
  1. Download and unpack OpenCV to a folder of your choice.
  2. opencv\sources now contains CMakeLists.txt and all the other files necessary. Configure the project in CMake. CLion users may just open CMakeLists.txt.

    • Fix 1: sprintf () family security error.
      Add add_definitions(-DSTRSAFE_NO_DEPRECATE) to the beginning of CMakeLists.txt. This will define STRSAFE_NO_DEPRECATE symbol for the project and suppress the error.
    • Fix 2: 'too many sections' as.exe error.
      Add the following lines to the beginning of CMakeLists.txt (source):

      set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wa,-mbig-obj")
      set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-Wa,-mbig-obj")
      
    • Fix 3: 'the last argument must be an 8-bit immediate'.
      Found nothing better than hardcoding 0x88 instead of mask_lo = _MM_SHUFFLE(2, 0, 2, 0) (binary 10 00 10 00) and 0xDD instead of mask_hi.
      As soon as my question gets a better answer, I will update this paragraph.
    • Fix 4: no c++11 threads in MinGW.
      Again, a dirty solution: added #include <mingw.*.h> to <mutex>, <thread>, <condition_variable> before #endif // C++11. (Source)
  3. Build it! It will take about 30-40 minutes.
  4. Find the output folder. It is still a mess but contains a Makefile.
    Launch cmd, cd to the output folder and call [path to compiler]\mingw32-make.exe install. (Source)
  5. Voila, your library is in the install folder! Now you can move it to a desired destination and set up environment variables.
Community
  • 1
  • 1
Alex
  • 1,077
  • 9
  • 24
  • how to solve this error http://stackoverflow.com/questions/41930349/opencv-installation-error-while-mingw32-make-on-windows – Amarnath R Jan 30 '17 at 09:51