Problem when compiling into static libraries with GTK+ support for RPiv4

Greetings everyone,

I’m currently facing issues cross-compiling OpenCV with GTK support. First of all, I’m a complete beginner with OpenCV.

Why I would like to use OpenCV :

I want to develop (in C++) and deploy a basic program that captures video input with the help of the videoio module. Target platform is Raspberry Pi v4 running on Raspbian GNU/Linux 10 (buster), and video input is Camera Module v2. I want to be able to develop from host PC (Ubuntu 20.04 LTS VM atm) and deploy binary with scp to target.

What I tried :

At the moment I’m still trying to build OpenCV on RPi, not even considering cross-compiling, with GTK :

cmake -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF -DCMAKE_TOOLCHAIN_FILE=…/…/opencv/platforms/linux/arm-gnueabi.toolchain.cmake -DCMAKE_INSTALL_PREFIX=…/third_party/opencv -DWITH_V4L=ON -DWITH_TBB=ON -DWITH_QT=OFF -DWITH_GTK=ON -DWITH_OPENCL=OFF -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON …/…/opencv

The issue :

The problem I’m facing is that despite specifying -DWITH_GTK=ON I end up with the following configuration lines :

– GUI:
     – GTK+: NO

After investigation, I’ve found that CMake uses the macro ocv_check_modules(define) which itself uses pkg_check_modules(${define}) to find if GTK+ is installed or not (macro is defined in cmake/OpenCVUtils.cmake).
But because I specified the -DBUILD_SHARED_LIBS=OFF (for cross-compilation purpose), pkg-config is disabled :

OpenCV disables pkg-config to avoid using of host libraries.

Additionally, this sentence is followed by :

Consider using PKG_CONFIG_LIBDIR to specify target SYSROOT

I’ve never used the --sysroot option neither, but from what I understand this option is used so that RPi root file system is specified as the root directory to look for libraries. This implies that when I’ll actually want to cross-compile from host, RPi will need to be reachable right ?

So my questions are :

Do you know how can I build OpenCV with DBUILD_SHARED_LIBS=OFF and -DWITH_GTK=ON.
Is there no other way but to use sysroot here ? (which I have actually no idea if it would work or not)

Note :

I also tried wit QT but I needed to cross-compile QT on my host machine and then specify OpenCV where to look for the correct QT CMake with the correct target architecture specified etc., but I had a bunch of other problems with this, so I thought it would be easier with GTK and here I am :tired_face:

Thank you for reading, best regards.

TL;DR: I’m trying to build OpenCV into static libraries but I can’t manage to do so with GUI (GTK) support.

1 Like