OpenGL error during Qt 6 corss compilation for Raspberry Pi 4

Viewed 449

I am trying to cross compile Qt 6 for Raspberry Pi 4. Following are the steps I follwed.
  1. installed crosstool-ng and related packages.
  2. took the rpi toolchain from https://github.com/ali1234/rpi-toolchain and build the same.
  3. downloaded the qt 6 source code by following the steps mentioned in https://wiki.qt.io/Building_Qt_6_from_Git.
  4. Compiled qt 6 successfully for the host system (Ubuntu 20.04 LTS).
  5. created a toolchain.cmake:
    toolchain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(tools $HOME/rpi-sdk/toolchain-raspbian--x86_64-arm-linux-gnueabihf)

set(CMAKE_SYSROOT $HOME/rpi-sdk/sysroot)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
  1. using rsync -avz pi@rpi_ip:/lib rsync -avz pi@192.168.0.119:/usr copied the files from target device(rpi 4) to create the sysroot
  2. Got the qt source code and compiled the same for host system (ubunto 20.04) sucessfully.
  3. For rpi cross compilation added folder "linux-arm-gnueabihf-g++" under qtbase/mkspecs and made following changes to qmake.conf
# qmake configuration for building with arm-linux-gnueabihf-g++
#

MAKEFILE_GENERATOR      = UNIX
CONFIG                 += incremental
QMAKE_INCREMENTAL_STYLE = sublib

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)

# modifications to g++.conf
QMAKE_CC                = arm-linux-gnueabihf-gcc
QMAKE_CXX               = arm-linux-gnueabihf-g++
QMAKE_LINK              = arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB        = arm-linux-gnueabihf-g++

# modifications to linux.conf
QMAKE_AR                = arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY           = arm-linux-gnueabihf-objcopy
QMAKE_NM                = arm-linux-gnueabihf-nm -P
QMAKE_STRIP             = arm-linux-gnueabihf-strip

QMAKE_INCDIR_OPENGL     = $HOME/rpi-sdk/sysroot/usr/include
QMAKE_LIBDIR_OPENGL     = $HOME/rpi-sdk/sysroot/usr/lib/arm-linux-gnueabihf
QMAKE_INCDIR_OPENGL_ES2 = $$QMAKE_INCDIR_OPENGL
QMAKE_LIBDIR_OPENGL_ES2 = $$QMAKE_LIBDIR_OPENGL
QMAKE_LIBS_OPENGL       = -lGL
QMAKE_LIBS_OPENGL_ES2   = -lGLESv2

load(qt_config)
  1. I can see the opengl libraries under rpi-sdk/sysroot/usr/lib/arm-linux-gnueabihf and rpi-sdk/sysroot/lib/arm-linux-gnueabihf. As per my understanding sysroot/lib is a link to sysroot/usr/lib
  2. Using following command to configure for cross compilation:
    qtbase/configure -release -opengl es2 -nomake examples -nomake tests -qt-host-path $HOME/QT_COMPILATION/qt-host -extprefix $HOME/QT_COMPILATION/qt-rpi -prefix $HOME/QT_COMPILATION/qt-rpi -- -DCMAKE_TOOLCHAIN_FILE=$HOME/rpi-sdk/toolchain.cmake -DQT_BUILD_TOOLS_WHEN_CROSSCOMPILING=ON

I am getting following errors:

ERROR: The OpenGL functionality tests failed!  You might need to modify the include and library search paths by editing QMAKE_INCDIR_OPENGL[_ES2], QMAKE_LIBDIR_OPENGL[_ES2] and QMAKE_LIBS_OPENGL[_ES2] in the mkspec for your platform.

CMake Error at cmake/QtBuildInformation.cmake:72 (message):
  Check the configuration messages for an error that has occurred.
Call Stack (most recent call first):
  cmake/QtBuildInformation.cmake:10 (qt_configure_print_summary)
  cmake/QtBuildInternals/QtBuildInternalsConfig.cmake:365 (qt_print_feature_summary)
  CMakeLists.txt:132 (qt_build_repo_end)

Please let me know if anything wrong I am doing here.

2 Answers

I was running into the same problem, then found this article: https://www.tal.org/tutorials/building-qt-62-raspberry-pi.

Adding options for opengles should fix the problem:

$HOME/qt-cross/qtbase/configure -release -opengl es2 -nomake examples -nomake tests \
  -qt-host-path $HOME/qt-host                              \
  -extprefix $HOME/qt6-rpi                                 \
  -prefix /usr/local/qt6                                   \
  -- -DCMAKE_TOOLCHAIN_FILE=$HOME/qt-cross/toolchain.cmake \
  -- -DQT_FEATURE_opengles2=ON                             \
  -- -DQT_FEATURE_opengles3=ON

Alternatively, you can use CMake directly:

cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DINPUT_opengl=es2 -DQT_BUILD_EXAMPLES=OFF -DQT_BUILD_TESTS=OFF \
  -DQT_HOST_PATH=$HOME/qt-host                           \
  -DCMAKE_STAGING_PREFIX=$HOME/qt6-rpi                   \
  -DCMAKE_INSTALL_PREFIX=/usr/local/qt6                  \
  -DQT_FEATURE_opengles2=ON                              \
  -DQT_FEATURE_opengles3=ON                              \
  -DCMAKE_TOOLCHAIN_FILE=$HOME/qt-cross/toolchain.cmake  \
  $HOME/qt-cross/qtbase

Note that this uses the default paths described in https://doc-snapshots.qt.io/qt6-dev/configure-linux-device.html; you want to adapt this to your specific situation.

Try adding the following lines on your toolchain.cmake file:

set(GL_INC_DIR ${CMAKE_SYSROOT}/usr/include)
set(GL_LIB_DIR ${CMAKE_SYSROOT}:${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/:${CMAKE_SYSROOT}/usr:${CMAKE_SYSROOT}/usr/lib)

set(EGL_INCLUDE_DIR ${GL_INC_DIR})
set(EGL_LIBRARY ${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/libEGL.so)

set(OPENGL_INCLUDE_DIR ${GL_INC_DIR})
set(OPENGL_opengl_LIBRARY ${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/libOpenGL.so)

set(GLESv2_INCLUDE_DIR ${GL_INC_DIR})
set(GLIB_LIBRARY ${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/libGLESv2.so)

set(GLESv2_INCLUDE_DIR ${GL_INC_DIR})
set(GLESv2_LIBRARY ${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/libGLESv2.so)

set(gbm_INCLUDE_DIR ${GL_INC_DIR})
set(gbm_LIBRARY ${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/libgbm.so)

set(Libdrm_INCLUDE_DIR ${GL_INC_DIR})
set(Libdrm_LIBRARY ${CMAKE_SYSROOT}/usr/lib/aarch64-linux-gnu/libdrm.so)

You might want to adjust the path according to your own use case, but the idea here is to point CMake into the correct OpenGL libraries from your sysroot directory.

Related