Hello there. I tried to build OpenCV with Code::Blocks (version 20.03) but had the following error.
I used MSYS2 to install MingW and GCC, and I want to build OpenCV 4.6.
This is my GCC version
$ gcc --version
gcc.exe (Rev6, Built by MSYS2 project) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
And this is the error log from Code::Blocks.
mingw32-make.exe[2]: *** No rule to make target âzlibâ, needed by âbin/libopencv_imgcodecs460.dllâ. Stop.
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:2362: modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
mingw32-make.exe: *** [D:/Cpp_Dev/OpenCV_CodeBlocks/Makefile:165: all] Error 2
mingw32-make.exe[2]: Leaving directory âD:/Cpp_Dev/OpenCV_CodeBlocksâ
mingw32-make.exe[1]: Leaving directory âD:/Cpp_Dev/OpenCV_CodeBlocksâ
Process terminated with status 2 (19 minute(s), 51 second(s))
2 error(s), 22 warning(s) (19 minute(s), 51 second(s))
Seems that something is wrong with ZLIB. I enabled the BUILD_ZLIB option at CMake Gui. I checked the OpenCV source file that I used with CMake Gui and zlib folder exists inside the 3rd party folder. Does anyone know how to fix this error?
please. no screenshots of code or errors here (they are all useless),
kindly replace with TEXT, thank you
(your image also does not show the real compile error, which must be a few lines above, please look again !)
we also need to know, which opencv / g++ versions you try to use
At CMake, I only have BUILD_ZLIB option also I enabled OPENCV_FORCE_3RDPARTY_BUILD too but it did not work.
CMake GUI generate output:
Summary
ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default.
Detected processor: AMD64
libjpeg-turbo: VERSION = 2.1.2, BUILD = opencv-4.6.0-libjpeg-turbo
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.6.0-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version â2.4.0â)
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT JVM)
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
Consider adding OPENCV_ALLOCATOR_STATS_COUNTER_TYPE=int/int64_t according to your build configuration
Registering hook âINIT_MODULE_SOURCES_opencv_dnnâ: C:/Users/batuh/Downloads/opencv-4.6.0/opencv-4.6.0/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
opencv_dnn: filter out cuda4dnn source code
Excluding from source files list: /modules/dnn/layers/layers_common.rvv.cpp
highgui: using builtin backend: WIN32UI
Found âmiscâ Python modules from C:/Users/batuh/Downloads/opencv-4.6.0/opencv-4.6.0/modules/python/package/extra_modules
Found âmat_wrapper;utilsâ Python modules from C:/Users/batuh/Downloads/opencv-4.6.0/opencv-4.6.0/modules/core/misc/python/package
Found âgapiâ Python modules from C:/Users/batuh/Downloads/opencv-4.6.0/opencv-4.6.0/modules/gapi/misc/python/package
General configuration for OpenCV 4.6.0 =====================================
Version control: unknown
OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching ts video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java python2 python3
Applications: tests perf_tests apps
Documentation: NO
Non-free algorithms: NO
Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES
Parallel framework: none
Trace: YES (built-in)
Other third-party libraries:
Lapack: NO
Eigen: YES (ver 3.4.0)
Custom HAL: NO
Protobuf: build (3.19.1)
OpenCL: YES (no extra features)
Include path: C:/Users/batuh/Downloads/opencv-4.6.0/opencv-4.6.0/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Building with MingW seems to have lots of problems. Fortunately, there are lots of third party builds for it, if you donât need to build it yourself.
After some trial and error, I found a solution for myself. I am writing my cure down for the people who will check this topic later and they can try what I did.
Installed Code::Blocks using the version that is shipped with MingW (Besides that I did not install anything related to MingW).
Used Git GUI to clone the OpenCV repo.
Built OpenCV from source using CMake GUI by selecting CodeBlocks-Mingw (Havenât made any changes in the configuration window).
I opened the generated project in Code::Blocks, and build the library and binaries by using Code::Blocks.
Added required paths to Code::Blocksâ compiler options and Windowsâ Environmental Variables.
Everything works well but the GCC/G++ shipped with Code::Blocks is 8.1.
Iâll try to find a solution that works with the current GCC and latest Code::Blocks and then I will post it here as a detailed guide. Thanks to everyone who tried to help.