#1147505 darknet: FTBFS with OpenCV 5.0

#1147505#5
Date:
2026-09-12 14:49:56 UTC
From:
To:
Dear maintainer,

Your package fails to build from source against opencv 5.0.0+dfsg-1~exp1,
currently in experimental.

OpenCV 5.0 renames its entire install tree from opencv4 to opencv5 and ships
no compatibility shims:

  * pkg-config: only /usr/lib/<triplet>/pkgconfig/opencv5.pc.  There is no
                opencv4.pc and no opencv.pc.
  * headers:    /usr/include/opencv5/opencv2/..., no /usr/include/opencv4.
  * cmake:      /usr/lib/<triplet>/cmake/opencv5/OpenCVConfig.cmake.  A bare
                find_package(OpenCV) still resolves, but a pinned version
                such as find_package(OpenCV 4.7) no longer matches.
  * modules:    libopencv-calib3d-dev is split into libopencv-calib-dev,
                libopencv-geometry-dev, libopencv-stereo-dev and
                libopencv-ptcloud-dev; libopencv-features2d-dev becomes
                libopencv-features-dev.  The CMake component names change
                with them (features2d -> features).
  * geometry:   the new geometry module is not only a piece of calib3d.  It
                also absorbs shape and contour functions that used to live
                in imgproc -- contourArea, arcLength, approxPolyDP,
                boundingRect, minAreaRect, convexHull and
                getPerspectiveTransform among them -- and opencv2/opencv.hpp
                does not pull in opencv2/geometry.hpp, so code that reached
                those through the umbrella header now needs an explicit
                include of opencv2/geometry.hpp.

darknet fails because its top-level Makefile (rule for
obj/image_opencv.o at Makefile:86) builds the OpenCV cflags with
`pkg-config --cflags opencv 2> /dev/null || pkg-config --cflags
opencv4`, and under OpenCV 5 neither the legacy "opencv" nor the
"opencv4" pkg-config name exists, so the substitution expands to
nothing. src/image_opencv.cpp:5 then fails with "fatal error:
opencv2/opencv.hpp: No such file or directory" because no -I path was
passed to gcc. The Makefile (and the matching CFLAGS/LDFLAGS logic for
`pkg-config --libs`) should query `opencv5` first, e.g. `pkg-config
--cflags opencv5 2>/dev/null || pkg-config --cflags opencv4 2>/dev/null
|| pkg-config --cflags opencv`, or be switched to detect the OpenCV
major version and include <opencv2/opencv.hpp> from
/usr/include/opencv5 accordingly.

The same source builds fine in the same chroot against the OpenCV 4.10
packages currently in unstable, so this is specific to OpenCV 5.

The relevant part of the build log follows; the full log is attached.


  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package opencv4 was not found in the pkg-config search path.
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  Package 'opencv4' not found
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  ./src/image_opencv.cpp:5:10: fatal error: opencv2/opencv.hpp: No
such file or directory
      5 | #include "opencv2/opencv.hpp"
        |          ^~~~~~~~~~~~~~~~~~~~
  compilation terminated.
  make[2]: *** [Makefile:86: obj/image_opencv.o] Error 1
  make[2]: *** Waiting for unfinished jobs....
  Package opencv4 was not found in the pkg-config search path.
  Perhaps you should add the directory containing `opencv4.pc'
  to the PKG_CONFIG_PATH environment variable
  Package 'opencv4' not found
  ./examples/cifar.c: In function ‘test_cifar’:
  ./examples/cifar.c:137:11: warning: variable ‘avg_top5’ set but not
used [-Wunused-but-set-variable=]
    137 |     float avg_top5 = 0;
        |           ^~~~~~~~
  ./examples/tag.c: In function ‘test_tag’:
  ./examples/tag.c:97:13: warning: ‘strncpy’ specified bound 256
equals destination size [-Wstringop-truncation]
     97 |             strncpy(input, filename, 256);
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./examples/super.c: In function ‘test_super’:
  ./examples/super.c:78:13: warning: ‘strncpy’ specified bound 256
equals destination size [-Wstringop-truncation]
     78 |             strncpy(input, filename, 256);
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./examples/captcha.c: In function ‘test_captcha’:
  ./examples/captcha.c:105:13: warning: ‘strncpy’ specified bound 256
equals destination size [-Wstringop-truncation]
    105 |             strncpy(input, filename, 256);
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./examples/lsd.c: In function ‘test_lsd’:
  ./examples/lsd.c:1315:13: warning: ‘strncpy’ specified bound 256
equals destination size [-Wstringop-truncation]
   1315 |             strncpy(input, filename, 256);
        |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  In file included from ./src/image.c:9:
  ./src/stb_image.h: In function ‘stbi__parse_png_file’:
  ./src/stb_image.h:4815:56: warning: writing 1 byte into a region of
size 0 [-Wstringop-overflow=]
   4815 |                   for (k = 0; k < s->img_n; ++k) tc[k] =
(stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth];
// non 8-bit images will be larger
        |
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./src/stb_image.h:4734:25: note: at offset 3 into destination object
‘tc’ of size 3
   4734 |    stbi_uc has_trans=0, tc[3];
        |                         ^~
  make[2]: Leaving directory
'/build/reproducible-path/darknet-0.0.0+git20180914.61c9d02e'
  dh_auto_build: error: make -j40 INSTALL="install
--strip-program=true" OPENCV=1 returned exit code 2
  make[1]: *** [debian/rules:27: override_dh_auto_build] Error 25
  make[1]: Leaving directory
'/build/reproducible-path/darknet-0.0.0+git20180914.61c9d02e'
  make: *** [debian/rules:18: binary] Error 2
  dpkg-buildpackage: error: debian/rules binary subprocess failed with
exit status 2
  --------------------------------------------------------------------------------

Please close this bug if it turns out to be a collision with another ongoing
transition rather than an OpenCV 5 problem.

Thanks,
Aron