如何在Windows上使用MinGW构建OpenCV 3.2.0

3
这篇文章包含我(以及其他用户)在从源代码构建库时遇到的所有问题。由于没有教程,因此我决定创建这种常见问题解答帖子,将所有解决方案放在一起。希望能够帮到你! 配置: OpenCV 3.2.0 MinGW-w64 x86_64-6.1.0-win32-seh-rt_v5-rev0
欢迎在答案中添加更多信息,因为将所有内容放在一个地方更加方便。

哇,太棒了!你知道如何在Windows环境下使用Python中的dlib和OpenCV吗? - Jeru Luke
这可能适用于StackOver文档,但它不是一个有效的问题。 - usr1234567
@usr1234567 这是一个旨在提问和回答的问题。我认为需要一些更好的解决方案来处理错误3和4,才可以成为一篇文档。 - Alex
@JeruLuke,不幸的是,我没有... - Alex
@Alex 或许你可以在 文档 部分记录这个答案。这样的内容不应该被浪费。 - Jeru Luke
1
据我所知,这个问题只会被关闭,而不是删除。一旦它提供的解决方案足够好,我可能会将其移动到文档中。文档是用于文档的 :) - Alex
1个回答

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.

如何解决这个错误 https://dev59.com/Zp7ha4cB1Zd3GeqPmql1 - Amarnath R

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接