简体   繁体   中英

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

after this i open C:\\opencv\\source\\opencv\\build this folder and right click on it and open powershell and typed mingw32-make commnd.

so that Mingw will start compiling OpenCV but after 5% error popout there...

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/ libjpeg-turbo.dir/all] Error 2 Makefile:161: recipe for target 'all' failed mingw32-make: *** [all] Error 2

Actually it is possible to compile opencv 3.4.3 by mingw32 (i have used 5.3.0 for the instance). Follow this guide. It is little bit old but works even for opencv 3.4.3 Steps to build:

  1. Download last Opencv version from the official github repo (let suppose you have downloaded opencv into "opencv" directory somewhere on your disk)
  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
  3. Install CMake (I have used 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"
  5. Select from the dialog "Mingw Makefiles" and wait utill sources will be preprocessed
  6. All options are red is normal, check "Grouped" in right top region of the CMake window, now we should check some flags:

    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

    in group ENABLE: check ENABLE_CXX11 and uncheck ENABLE_PRECOMPILED_HEADERS

    in group WITH: uncheck 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)

  9. Make shure your mingw toolchain location is known for your system (look if system environment variable PATH contains path to mingw toolchain)

  10. Open cmd.exe, change directory to your opencv's build idrectory

  11. Let's build opencv (-j[uint] - option specifies number of threads to use)

    .../build> mingw32-make -j4

  12. Let's install opencv

    .../build> mingw32-make install

  13. Done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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