opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.42k stars 5.76k forks source link

Building OpenCV Contrib 4.5.4 from source along with LibTiff4 #3114

Open matanox opened 2 years ago

matanox commented 2 years ago

System information (version)

Build failure description

I am using BUILD_TIFF=ON as on my (Ubuntu 20.04) system the globally installed libtiff is version 5 not 4, so this allows building OpenCV without downgrading from the distro default version of LibTiff. This has indeed avoided linking errors when building OpenCV without contrib in my case. However, building along with OpenCV using the -DBUILD_TIFF flag set to on, seems to still bump into linkage errors relating to LibTiff version 4:

$ cmake -DWITH_OPENEXR=OFF -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ -DBUILD_TIFF=ON ../opencv

Linking CXX executable ../../bin/opencv_test_text
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFGetFieldDefaulted@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFCleanup@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFReadRGBAImageOriented@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFOpen@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFSetSubDirectory@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFSetField@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFCurrentDirOffset@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFPrintDirectory@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFGetField@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFSetDirectory@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFReadScanline@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFClose@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFClientOpen@LIBTIFF_4.0'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/liblept.so.5: undefined reference to `TIFFGetVersion@LIBTIFF_4.0'
collect2: error: ld returned 1 exit status

If my hunch after a few hours' battle with linking OpenCV with Contrib is correct, I just wonder whether contrib builds against the LibTiff that gets dynamically built as part of the OpenCV build courtesy of that flag.

That said to be honest, I'm a bit confused seeing the following libtiff linking information for the offending library:

$ ldd /usr/lib/x86_64-linux-gnu/liblept.so.5
.
.
.
lbtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007fbd367bb000)

Steps to reproduce

matanox commented 2 years ago

This issue does not occur when jointly building the 4.2.0 tags of OpenCV and Contrib rather than 4.5.4. But for flexibly catching up as time goes by, I hope it would become possible to build 4.5.4 or subsequent release tags, even on Ubuntu 20.04 ...

In particular, maybe it might be as simple as making contrib use the same copy of LibTiff4 that's being built from source as part of the OpenCV build, or conversely upgrading them both to use LibTiff5, whichever make more sense in the overall of all platforms etc.

A workaround for 4.5.4 as such would be greatly appreciated as well.

alalek commented 2 years ago

liblept.so.5: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'

There is 3rdparty library which want to use some own libtiff version. Successful build requires properly configuration with using of the same version of libtiff everywhere (in OpenCV and its dependencies). Refer to CMake scripts how to do that and/or install libtiff development packages.

-DBUILD_TIFF=ON

Using non-default build options means that you understand that you are doing... This flag forces OpenCV to build own libtiff from the embedded source code instead of using "system default".


Possible workaround is -DWITH_TESSERACT=OFF to drop lept from dependencies.


This is a configuration issue - it can't be resolved in OpenCV. Build / usage questions should go to Users OpenCV Q/A forum: https://forum.opencv.org/