简体   繁体   English

mingw 为 C++ 编译 opencv 时出现错误?

[英]i am getting error while mingw is compiling opencv for c++?

okay i was trying setup an environment for human detection program.. programming language i will use is c++ and compiler is code blocks.. i have downloaded opencv 4.1 also downloaded CMake and mingw i have also added path in environment setting.. i extracted opencv in c:\\opencv\\sources folder and by using cmake i have configured and generated build files in c:\\opencv\\build好的,我正在尝试为人体检测程序设置环境..我将使用的编程语言是 c++,编译器是代码块..我已经下载了 opencv 4.1 也下载了 CMake 和 mingw 我还在环境设置中添加了路径..我提取了 opencv在 c:\\opencv\\sources 文件夹中,并通过使用 cmake 我在 c:\\opencv\\build 中配置并生成了构建文件

after this i open C:\\opencv\\source\\opencv\\build this folder and right click on it and open powershell and typed mingw32-make commnd.在此之后我打开 C:\\opencv\\source\\opencv\\build 这个文件夹并右键单击它并打开 powershell 并输入 mingw32-make commnd。

so that Mingw will start compiling OpenCV but after 5% error popout there...这样 Mingw 将开始编译 OpenCV,但在 5% 的错误弹出后...

PS C:\opencv\source\opencv\build> mingw32-make

[ 2%] Built target zlib [ 2%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jmemmgr.c.obj C:\\opencv\\source\\opencv\\sources\\3rdparty\\libjpeg-turbo\\src\\jmemmgr.c: In function 'realize_virt_arrays': C:\\opencv\\source\\opencv\\sources\\3rdparty\\libjpeg-turbo\\src\\jmemmgr.c:662:11: error: 'SIZE_MAX' undeclared (first use in this function) if (SIZE_MAX - maximum_space < new_space) ^~~~~~~~ C:\\opencv\\source\\opencv\\sources\\3rdparty\\libjpeg-turbo\\src\\jmemmgr.c:662:11: note: each undeclared identifier is reported only once for each function it appears in 3rdparty\\libjpeg-turbo\\CMakeFiles\\libjpeg-turbo.dir\\build.make:678: recipe for target '3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jmemmgr.c.obj' failed mingw32-make[2]: * [3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jmemmgr.c.obj] Error 1 CMakeFiles\\Makefile2:312: recipe for target '3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/all' failed mingw32-make[1]: * [3rdparty/libjpeg-turbo/CMakeFiles/ [ 2%] 构建目标 zlib [ 2%] 构建 C 对象 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jmemmgr.c.obj C:\\opencv\\source\\opencv\\sources\\3rdparty\\libjpeg- turbo\\src\\jmemmgr.c: 在函数 'realize_virt_arrays': C:\\opencv\\source\\opencv\\sources\\3rdparty\\libjpeg-turbo\\src\\jmemmgr.c:662:11: 错误:'SIZE_MAX' 未声明(第一次使用在这个函数中) if (SIZE_MAX - maximum_space < new_space) ^~~~~~~~ C:\\opencv\\source\\opencv\\sources\\3rdparty\\libjpeg-turbo\\src\\jmemmgr.c:662:11: 注意:每个对于出现在 3rdparty\\libjpeg-turbo\\CMakeFiles\\libjpeg-turbo.dir\\build.make:678: recipe for target '3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/ 中的每个函数,未声明的标识符仅报告一次src/jmemmgr.c.obj' failed mingw32-make[2]: * [3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jmemmgr.c.obj] 错误 1 ​​CMakeFiles\\Makefile2:312: recipe for目标 '3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/all' 失败 mingw32-make[1]: * [3rdparty/libjpeg-turbo/CMakeFiles/ libjpeg-turbo.dir/all] Error 2 Makefile:161: recipe for target 'all' failed mingw32-make: *** [all] Error 2 libjpeg-turbo.dir/all] 错误 2 Makefile:161: 目标 'all' 的配方失败 mingw32-make: *** [all] 错误 2

Actually it is possible to compile opencv 3.4.3 by mingw32 (i have used 5.3.0 for the instance).实际上可以通过 mingw32 编译 opencv 3.4.3(我使用了 5.3.0 作为实例)。 Follow this guide.遵循本指南。 It is little bit old but works even for opencv 3.4.3 Steps to build:它有点旧但甚至适用于 opencv 3.4.3 构建步骤:

  1. Download last Opencv version from the official github repo (let suppose you have downloaded opencv into "opencv" directory somewhere on your disk)从官方 github 存储库下载最新的 Opencv 版本(假设您已将 opencv 下载到磁盘上的“opencv”目录中)
  2. Go to opencv/modules/videoio/src, open cap_dshow.hpp, paste #define NO_DSHOW_STRSAFE (right on top of all other), save file to commit changes转到 opencv/modules/videoio/src,打开 cap_dshow.hpp,粘贴 #define NO_DSHOW_STRSAFE(在所有其他文件的顶部),保存文件以提交更改
  3. Install CMake (I have used 3.5.1)安装 CMake(我用过 3.5.1)
  4. Open CMake, point Opencv3.4.3 sources location also point where you want to build them (let suppose for the instance it would be "build" directory sonwhere on your disk), press "Configure button"打开 CMake,指向 Opencv3.4.3 源位置也指向您想要构建它们的位置(假设该实例将是磁盘上的“构建”目录),按“配置按钮”
  5. Select from the dialog "Mingw Makefiles" and wait utill sources will be preprocessed从对话框中选择“Mingw Makefiles”并等待源代码将被预处理
  6. All options are red is normal, check "Grouped" in right top region of the CMake window, now we should check some flags:所有选项都是红色是正常的,在 CMake 窗口的右上角区域检查“分组”,现在我们应该检查一些标志:

    in group CMAKE: for option CMAKE_BUILD_TYPE write Release (to build release version of opencv), also here you can specify where you want Opencv binaries will be installed after build在 CMAKE 组中:对于选项 CMAKE_BUILD_TYPE 写入 Release(以构建 opencv 的发布版本),您也可以在此处指定构建后将安装 Opencv 二进制文件的位置

    in group ENABLE: check ENABLE_CXX11 and uncheck ENABLE_PRECOMPILED_HEADERS在组 ENABLE 中:选中 ENABLE_CXX11 并取消选中 ENABLE_PRECOMPILED_HEADERS

    in group WITH: uncheck WITH_MSMF在组中:取消选中 WITH_MSMF

  7. Press "Configure" button, whait untill processing will be complited, now all options should become white按“配置”按钮,直到处理完成,现在所有选项都应该变成白色

  8. Press "Generate" button and wait (in your build directory Makefile should be created, you can close CMake after this step)按“生成”按钮并等待(在您的构建目录中应创建 Makefile,您可以在此步骤后关闭 CMake)

  9. Make shure your mingw toolchain location is known for your system (look if system environment variable PATH contains path to mingw toolchain)确保您的 mingw 工具链位置为您的系统所知(查看系统环境变量 PATH 是否包含 mingw 工具链的路径)

  10. Open cmd.exe, change directory to your opencv's build idrectory打开 cmd.exe,将目录切换到你的 opencv 的构建目录

  11. Let's build opencv (-j[uint] - option specifies number of threads to use)让我们构建 opencv(-j[uint] - 选项指定要使用的线程数)

    .../build> mingw32-make -j4 .../build> mingw32-make -j4

  12. Let's install opencv让我们安装opencv

    .../build> mingw32-make install .../build> mingw32-make 安装

  13. Done完毕

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM