Cross compile Qt6 on raspberry pi
-
Hi,
I tried to cross compile Qt v6.1.0 for my raspberry pi 4 vith 64bit raspbian on it.
I follow this tutorial Cross-Compile Qt 6 for Raspberry PiI am on a virtual box in a linux ubuntu jellyfish 22.0.4.
I compiled only qt base for the beginning and the firt part of the operation (host compilation) was successfull
I am stuck to the cross compiling configure. When I run cmake a get errors
CMake Error at qtbase/src/corelib/Qt6CoreMacros.cmake:2061 (add_library): Target "Gui" links to target "GLESv2::GLESv2" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? Call Stack (most recent call first): qtbase/cmake/QtModuleHelpers.cmake:130 (_qt_internal_add_library) qtbase/src/gui/CMakeLists.txt:53 (qt_internal_add_module)
as I understand it seems that cmake cannot find GLESv2 library, but think my sysroot is correctly set and I can find the file libGLESv2.so in sysroot/usr/lib nd also in /opt/vc.
Although the sim links are correctly setI tried to find an answer on other forums but i did not found any post with a similar problem to mine.
I used this command../qt5/configure -release -opengl es2 -nomake examples -nomake tests -qt-host-path $HOME/qt-host -extprefix $HOME/qt-raspi -prefix /usr/local/qt6 -device linux-rasp-pi4-aarch64 -device-option CROSS_COMPILE=aarch64-linux-gnu- -- -DCMAKE_TOOLCHAIN_FILE=$HOME/toolchain.cmake -DQT_FEATURE_xcb=ON -DFEATURE_xcb_xlib=ON -DQT_FEATURE_xlib=ON -DQT_FEATURE_opengles2=ON
This is my toolchain file
cmake_minimum_required(VERSION 3.18) include_guard(GLOBAL) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(TARGET_SYSROOT /home/fangry/rpi-sysroot) set(CMAKE_SYSROOT ${TARGET_SYSROOT}) set(ENV{PKG_CONFIG_PATH} $PKG_CONFIG_PATH:/usr/lib/aarch64-linux-gnu/pkgconfig) set(ENV{PKG_CONFIG_LIBDIR} /usr/lib/pkgconfig:/usr/share/pkgconfig/:${TARGET_SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${TARGET_SYSROOT}/usr/lib/pkgconfig) set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT}) # if you use other version of gcc and g++ than gcc/g++ 9, you must change the following variables set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc-11) set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++-11) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${TARGET_SYSROOT}/usr/include") set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") set(QT_COMPILER_FLAGS "-march=armv8-a") set(QT_COMPILER_FLAGS_RELEASE "-O2 -pipe") set(QT_LINKER_FLAGS "-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed") 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) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_BUILD_RPATH ${TARGET_SYSROOT}) include(CMakeInitializeConfigs) function(cmake_initialize_per_config_variable _PREFIX _DOCSTRING) if (_PREFIX MATCHES "CMAKE_(C|CXX|ASM)_FLAGS") set(CMAKE_${CMAKE_MATCH_1}_FLAGS_INIT "${QT_COMPILER_FLAGS}") foreach (config DEBUG RELEASE MINSIZEREL RELWITHDEBINFO) if (DEFINED QT_COMPILER_FLAGS_${config}) set(CMAKE_${CMAKE_MATCH_1}_FLAGS_${config}_INIT "${QT_COMPILER_FLAGS_${config}}") endif() endforeach() endif() if (_PREFIX MATCHES "CMAKE_(SHARED|MODULE|EXE)_LINKER_FLAGS") foreach (config SHARED MODULE EXE) set(CMAKE_${config}_LINKER_FLAGS_INIT "${QT_LINKER_FLAGS}") endforeach() endif() _cmake_initialize_per_config_variable(${ARGV}) endfunction() set(XCB_PATH_VARIABLE ${TARGET_SYSROOT}) set(GL_INC_DIR ${TARGET_SYSROOT}/usr/include) set(GL_LIB_DIR ${TARGET_SYSROOT}:${TARGET_SYSROOT}/usr/lib/aarch64-linux-gnu/:${TARGET_SYSROOT}/usr:${TARGET_SYSROOT}/usr/lib) set(EGL_INCLUDE_DIR ${GL_INC_DIR}) set(EGL_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libEGL.so) set(OPENGL_INCLUDE_DIR ${GL_INC_DIR}) set(OPENGL_opengl_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libOpenGL.so) set(GLESv2_INCLUDE_DIR ${GL_INC_DIR}) set(GLIB_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libGLESv2.so) set(GLESv2_INCLUDE_DIR ${GL_INC_DIR}) set(GLESv2_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libGLESv2.so) set(gbm_INCLUDE_DIR ${GL_INC_DIR}) set(gbm_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libgbm.so) set(Libdrm_INCLUDE_DIR ${GL_INC_DIR}) set(Libdrm_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libdrm.so) set(XCB_XCB_INCLUDE_DIR ${GL_INC_DIR}) set(XCB_XCB_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libxcb.so)
Could you help me to understand what happened and help me to achieve this cross compile.
Thank you
-
Hi,
I tried to cross compile Qt v6.1.0 for my raspberry pi 4 vith 64bit raspbian on it.
I follow this tutorial Cross-Compile Qt 6 for Raspberry PiI am on a virtual box in a linux ubuntu jellyfish 22.0.4.
I compiled only qt base for the beginning and the firt part of the operation (host compilation) was successfull
I am stuck to the cross compiling configure. When I run cmake a get errors
CMake Error at qtbase/src/corelib/Qt6CoreMacros.cmake:2061 (add_library): Target "Gui" links to target "GLESv2::GLESv2" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? Call Stack (most recent call first): qtbase/cmake/QtModuleHelpers.cmake:130 (_qt_internal_add_library) qtbase/src/gui/CMakeLists.txt:53 (qt_internal_add_module)
as I understand it seems that cmake cannot find GLESv2 library, but think my sysroot is correctly set and I can find the file libGLESv2.so in sysroot/usr/lib nd also in /opt/vc.
Although the sim links are correctly setI tried to find an answer on other forums but i did not found any post with a similar problem to mine.
I used this command../qt5/configure -release -opengl es2 -nomake examples -nomake tests -qt-host-path $HOME/qt-host -extprefix $HOME/qt-raspi -prefix /usr/local/qt6 -device linux-rasp-pi4-aarch64 -device-option CROSS_COMPILE=aarch64-linux-gnu- -- -DCMAKE_TOOLCHAIN_FILE=$HOME/toolchain.cmake -DQT_FEATURE_xcb=ON -DFEATURE_xcb_xlib=ON -DQT_FEATURE_xlib=ON -DQT_FEATURE_opengles2=ON
This is my toolchain file
cmake_minimum_required(VERSION 3.18) include_guard(GLOBAL) set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(TARGET_SYSROOT /home/fangry/rpi-sysroot) set(CMAKE_SYSROOT ${TARGET_SYSROOT}) set(ENV{PKG_CONFIG_PATH} $PKG_CONFIG_PATH:/usr/lib/aarch64-linux-gnu/pkgconfig) set(ENV{PKG_CONFIG_LIBDIR} /usr/lib/pkgconfig:/usr/share/pkgconfig/:${TARGET_SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${TARGET_SYSROOT}/usr/lib/pkgconfig) set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT}) # if you use other version of gcc and g++ than gcc/g++ 9, you must change the following variables set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc-11) set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++-11) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${TARGET_SYSROOT}/usr/include") set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") set(QT_COMPILER_FLAGS "-march=armv8-a") set(QT_COMPILER_FLAGS_RELEASE "-O2 -pipe") set(QT_LINKER_FLAGS "-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed") 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) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_BUILD_RPATH ${TARGET_SYSROOT}) include(CMakeInitializeConfigs) function(cmake_initialize_per_config_variable _PREFIX _DOCSTRING) if (_PREFIX MATCHES "CMAKE_(C|CXX|ASM)_FLAGS") set(CMAKE_${CMAKE_MATCH_1}_FLAGS_INIT "${QT_COMPILER_FLAGS}") foreach (config DEBUG RELEASE MINSIZEREL RELWITHDEBINFO) if (DEFINED QT_COMPILER_FLAGS_${config}) set(CMAKE_${CMAKE_MATCH_1}_FLAGS_${config}_INIT "${QT_COMPILER_FLAGS_${config}}") endif() endforeach() endif() if (_PREFIX MATCHES "CMAKE_(SHARED|MODULE|EXE)_LINKER_FLAGS") foreach (config SHARED MODULE EXE) set(CMAKE_${config}_LINKER_FLAGS_INIT "${QT_LINKER_FLAGS}") endforeach() endif() _cmake_initialize_per_config_variable(${ARGV}) endfunction() set(XCB_PATH_VARIABLE ${TARGET_SYSROOT}) set(GL_INC_DIR ${TARGET_SYSROOT}/usr/include) set(GL_LIB_DIR ${TARGET_SYSROOT}:${TARGET_SYSROOT}/usr/lib/aarch64-linux-gnu/:${TARGET_SYSROOT}/usr:${TARGET_SYSROOT}/usr/lib) set(EGL_INCLUDE_DIR ${GL_INC_DIR}) set(EGL_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libEGL.so) set(OPENGL_INCLUDE_DIR ${GL_INC_DIR}) set(OPENGL_opengl_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libOpenGL.so) set(GLESv2_INCLUDE_DIR ${GL_INC_DIR}) set(GLIB_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libGLESv2.so) set(GLESv2_INCLUDE_DIR ${GL_INC_DIR}) set(GLESv2_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libGLESv2.so) set(gbm_INCLUDE_DIR ${GL_INC_DIR}) set(gbm_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libgbm.so) set(Libdrm_INCLUDE_DIR ${GL_INC_DIR}) set(Libdrm_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libdrm.so) set(XCB_XCB_INCLUDE_DIR ${GL_INC_DIR}) set(XCB_XCB_LIBRARY ${XCB_PATH_VARIABLE}/usr/lib/aarch64-linux-gnu/libxcb.so)
Could you help me to understand what happened and help me to achieve this cross compile.
Thank you
@Fangry said in Cross compile Qt6 on raspberry pi:
and I can find the file libGLESv2.so in sysroot/usr/lib
Can you also find its header files? For building library itself is not enough.
-
Hi,
@jsulm said in Cross compile Qt6 on raspberry pi:
@Fangry said in Cross compile Qt6 on raspberry pi:
and I can find the file libGLESv2.so in sysroot/usr/lib
Can you also find its header files? For building library itself is not enough.
I will check that immediately.
I also make more search and I find an start of an answer by reading this post
When I check the result of the tests have EGL and have GLES I found that errors occurs with the link with glibc
more precisely i have an undifined reference to function@glibc_private -
@Fangry said in Cross compile Qt6 on raspberry pi:
Hi,
@jsulm said in Cross compile Qt6 on raspberry pi:
@Fangry said in Cross compile Qt6 on raspberry pi:
and I can find the file libGLESv2.so in sysroot/usr/lib
Can you also find its header files? For building library itself is not enough.
I will check that immediately.
I also make more search and I find an start of an answer by reading this post
When I check the result of the tests have EGL and have GLES I found that errors occurs with the link with glibc
more precisely i have an undifined reference to function@glibc_privateSo I check my include sysroot and I have the include files correctly set.
I Check again the cmake error log and i found some error before have EGL.
More precisely from building files with ld.Performing C++ SOURCE FILE Test TEST_use_lld_linker failed with the following output: Change Dir: /home/fangry/qtpi-build/CMakeFiles/CMakeTmp Run Build Command(s):/usr/bin/ninja cmTC_a7ba6 && [1/2] Building CXX object CMakeFiles/cmTC_a7ba6.dir/src.cxx.o [2/2] Linking CXX executable cmTC_a7ba6 FAILED: cmTC_a7ba6 : && /usr/bin/aarch64-linux-gnu-g++-11 --sysroot=/home/fangry/rpi-sysroot -I/home/fangry/rpi-sysroot/usr/include -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fuse-ld=lld CMakeFiles/cmTC_a7ba6.dir/src.cxx.o -o cmTC_a7ba6 -Wl,-rpath,/home/fangry/rpi-sysroot && : collect2: fatal error: cannot find ‘ld’ compilation terminated. ninja: build stopped: subcommand failed. Source file was: int main() { return 0; } Performing C++ SOURCE FILE Test TEST_gdb_index failed with the following output: Change Dir: /home/fangry/qtpi-build/CMakeFiles/CMakeTmp Run Build Command(s):/usr/bin/ninja cmTC_88e8c && [1/2] Building CXX object CMakeFiles/cmTC_88e8c.dir/src.cxx.o [2/2] Linking CXX executable cmTC_88e8c FAILED: cmTC_88e8c : && /usr/bin/aarch64-linux-gnu-g++-11 --sysroot=/home/fangry/rpi-sysroot -I/home/fangry/rpi-sysroot/usr/include -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,--gdb-index CMakeFiles/cmTC_88e8c.dir/src.cxx.o -o cmTC_88e8c -Wl,-rpath,/home/fangry/rpi-sysroot && : /usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: unrecognized option '--gdb-index' /usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: use the --help option for usage information collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.
It seems that aarch64 gnu ld in version 11 does not take --gdb-index in option. how can i remove it frome build ?