Cross-compile Qt6 on Ubuntu 22.04

96 Views Asked by At

I'm having some troubles cross compiling Qt6 on Ubuntu 22.04 using mingw64 and CMake. The compilation process starts fine and all source files get compiled, but when I start looking for Qt components using

find_package(Qt6 REQUIRED COMPONENTS Core Widgets)

I get the following error message

CMake Error at build/CMakeModules/cmake/find_qt.cmake:31 (find_package):
  Found package configuration file:

    /home/vinci/Downloads/QtPlayground/build/_deps/qt6-build/lib/cmake/Qt6/Qt6Config.cmake

  but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
  FOUND.  Reason given by package:

  Failed to find Qt component "Core".

  Expected Config file at
  "/home/vinci/Downloads/QtPlayground/build/_deps/qt6-build/lib/cmake/Qt6Core/Qt6CoreConfig.cmake"
  exists

  Failed to find Qt component "Widgets".

  Expected Config file at
  "/home/vinci/Downloads/QtPlayground/build/_deps/qt6-build/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake"
  exists

So apparently it found the package I've compiled but still refuses to use it for whatever reason. Could this be related to Qt complaining about missing libraries at the beginning of the compilation? That's the only thing I found so far that looks strange to me. E.g. here it complains about ZLIB missing.

-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR) (Required is at least version "1.0.8")

I don't understand why though. My toolchain file points it to the mingw64 installation which I assume contains zlib?

set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)

# specify the cross compiler
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)

set(CMAKE_SYSROOT /usr/x86_64-w64-mingw32)

# where is the target environment
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
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(QT_HOST_PATH
    "/usr"
    CACHE PATH "host path for Qt")
set(Qt6HostInfo_DIR
    "/usr/lib/x86_64-linux-gnu/cmake/Qt6HostInfo"
    CACHE PATH "host path for Qt 6 info")

# set the resource compiler (RHBZ #652435)
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
set(CMAKE_MC_COMPILER x86_64-w64-mingw32-windmc)

# override boost thread component suffix as mingw-w64-boost is compiled with
# threadapi=win32
set(Boost_THREADAPI win32)

# These are needed for compiling lapack (RHBZ #753906)
set(CMAKE_Fortran_COMPILER x86_64-w64-mingw32-gfortran)
set(CMAKE_AR:FILEPATH x86_64-w64-mingw32-ar)
set(CMAKE_RANLIB:FILEPATH x86_64-w64-mingw32-ranlib)
0

There are 0 best solutions below