Building from source failing

Im building opencv from source on macOSX on python 3.10 with all the “extra” modules and I get this error:

[ 35%] Building CXX object modules/img_hash/CMakeFiles/opencv_img_hash.dir/src/radial_variance_hash.cpp.o
[ 35%] **Linking CXX shared library ../../lib/libopencv_img_hash.dylib**
[ 35%] Built target opencv_img_hash
make: *** [all] Error 2

that succeeded.

that piece of log does not contain the reason for the failure.

make likely ran build tasks in parallel. you should force it to a single task with -j1


again, the real error will be a couple of lines above, please show us.

Sry, I did not see it. Here it is:

make[2]: *** No rule to make target zlib', needed by lib/libopencv_imgcodecs.4.6.0.dylib’. Stop.
make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs…

I tried to in stall it with brew install zlib, however it is already installed: zlib 1.2.11 is already installed and up-to-date

rather let them build their own zlib (from opencv’s 3rdparty src), make sure, your cmake cmdline contains:


and try again

This time I ran:

cmake -DOPENCV_EXTRA_MODULES_PATH=/Users/username/Documents/CV2_Build/opencv_contrib/modules /Users/username/Documents/CV2_Build/opencv-4.x -DWITH_ZLIB=ON -DBUILD_ZLIB=ON

But I get:

make[2]: *** No rule to make target `zlib', needed by `lib/libopencv_imgcodecs.4.6.0.dylib'.  Stop.
make[1]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] Error 2
make: *** [all] Error 2

Can I maybe delete the files that give the error if they are not fundamental, I know that just deleting files will probably cause corruption more than fixing the issue, but I rarely complied a package before and my knowledge of what does what limited.

you probably should clean the build folder, and start again.