Code::Blocks OpenCV Build Error

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))

Those are my configuration steps.

Summary

Codeblocks_E2

Summary

Codeblocks_E4

Summary

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

Hello, I edited my message with appropriate information.

1 Like

is WITH_ZLIB=ON , too ? (cmake)

when in doubt, try with a clean build folder
(esp delete cmakecache.txt)

if that does not work, please show complete cmake output

1 Like

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

Platform:
Timestamp: 2022-12-22T18:03:04Z
Host: Windows 10.0.19044 AMD64
CMake: 3.24.1
CMake generator: MinGW Makefiles
CMake build tool: C:/PROGRA~1/CODEBL~1/MinGW/bin/mingw32-make.exe
Configuration: Release

CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (18 files): + SSSE3 SSE4_1
SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (33 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

C/C++:
Built as dynamic libs?: YES
C++ standard: 11
C++ Compiler: C:/msys64/mingw64/bin/c++.exe (ver 12.2.0)
C++ flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: C:/msys64/mingw64/bin/cc.exe
C flags (Release): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -fomit-frame-pointer -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -Wl,–gc-sections
Linker flags (Debug): -Wl,–gc-sections
ccache: NO
Precompiled headers: NO
Extra dependencies:
3rdparty dependencies:

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

Windows RT support: NO

GUI: WIN32UI
Win32 UI: YES
VTK support: NO

Media I/O:
ZLib: zlib (ver 1.2.12)
JPEG: build-libjpeg-turbo (ver 2.1.2-62)
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.37)
TIFF: build (ver 42 - 4.2.0)
JPEG 2000: build (ver 2.4.0)
OpenEXR: OpenEXR::OpenEXR (ver 3.1.5)
HDR: YES
SUNRASTER: YES
PXM: YES
PFM: YES

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

Python (for build): C:/msys64/mingw64/bin/python3.exe

Java:
ant: NO
JNI: NO
Java wrappers: NO
Java tests: NO

Install to: D:/Cpp_Dev/OpenCV_Codeblocks/install

Configuring done
Generating done

CMakeError.log

Summary

https://codefile.io/f/xwLbsPeMfL7AwAtnN3Aw

CMakeOutput.log

Summary

https://codefile.io/f/rugCjuVcLQuI1enQp1iu

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.

Would you please provide me with any examples?

rather try to git clone the opencv repo, so the 3rdparty resources are all in the expected place

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.

  1. Installed Code::Blocks using the version that is shipped with MingW (Besides that I did not install anything related to MingW).

  2. Used Git GUI to clone the OpenCV repo.

  3. Built OpenCV from source using CMake GUI by selecting CodeBlocks-Mingw (Haven’t made any changes in the configuration window).

  4. I opened the generated project in Code::Blocks, and build the library and binaries by using Code::Blocks.

  5. 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.