# Code::Blocks OpenCV Build Error

**URL:** <https://forum.opencv.org/t/code-blocks-opencv-build-error/11383>\
**Category:** C++\
**Tags:** build, programming\
**Created:** [December 21, 2022, 8:13pm UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383 "2022-12-21T20:13:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lightbringer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lightbringer/32/121_2.png) [@lightbringer](https://forum.opencv.org/u/lightbringer)\
**Post date:** [December 21, 2022, 8:13pm UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/1 "2022-12-21T20:13:57Z")

</div>

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](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/c/ca2bdd9f41e4fdbe70a788cfca0d67eb80b42ea1.png)

> **Summary**
>
> ![Codeblocks_E4](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/7/710d75208d86665c548124f82629c5c26e715bad.png)

> **Summary**
>
> ![Codeblocks_E3](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/7/722a66c731358160e583fde0b654f03b8aa63ffc.png)

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?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [December 22, 2022, 6:34am UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/2 "2022-12-22T06:34:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lightbringer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lightbringer/32/121_2.png) [@lightbringer](https://forum.opencv.org/u/lightbringer)\
**Post date:** [December 22, 2022, 1:07pm UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/4 "2022-12-22T13:07:21Z")

</div>

Hello, I edited my message with appropriate information.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [December 22, 2022, 5:18pm UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/5 "2022-12-22T17:18:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lightbringer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lightbringer/32/121_2.png) [@lightbringer](https://forum.opencv.org/u/lightbringer)\
**Post date:** [December 22, 2022, 6:23pm UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/6 "2022-12-22T18:23:41Z")

</div>

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](http://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](https://codefile.io/f/xwLbsPeMfL7AwAtnN3Aw)

CMakeOutput.log

> **Summary**
>
> [https://codefile.io/f/rugCjuVcLQuI1enQp1iu](https://codefile.io/f/rugCjuVcLQuI1enQp1iu)

---

<div class="post-metadata">

**Author:** ![matti.vuori](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@matti.vuori](https://forum.opencv.org/u/matti.vuori)\
**Post date:** [December 23, 2022, 5:43pm UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/7 "2022-12-23T17:43:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lightbringer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lightbringer/32/121_2.png) [@lightbringer](https://forum.opencv.org/u/lightbringer)\
**Post date:** [December 24, 2022, 8:06am UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/8 "2022-12-24T08:06:53Z")

</div>

Would you please provide me with any examples?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [December 24, 2022, 10:34am UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/9 "2022-12-24T10:34:56Z")

</div>

> [@lightbringer](#):
>
> ocv\_init\_download: OpenCV source tree is not fetched as git repository. 3rdparty

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

---

<div class="post-metadata">

**Author:** ![lightbringer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/lightbringer/32/121_2.png) [@lightbringer](https://forum.opencv.org/u/lightbringer)\
**Post date:** [December 25, 2022, 8:19pm UTC](https://forum.opencv.org/t/code-blocks-opencv-build-error/11383/10 "2022-12-25T20:19:47Z")

</div>

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.
