Cannot build a Qt6 app with snapcraft

I’m attempting to build a simple Qt 6 app as a snap. Ideally it should run on Ubuntu Core in U. Frame but just successfully building and running it on my Ubuntu Desktop (22.04.1) would be a huge step forward.

My snapcraft.yaml:

name: hello-qt
version: 0.0.1
summary: Qt6 example app
description: Qt example app
confinement: strict
grade: stable
base: core22
architectures:
  - amd64
apps:
  qt-hello:
    common-id: org.foobar.qt-hello
    command: qt-hello
    daemon: simple
    restart-condition: always
    plugs:
      - opengl # do I need opengl?
      - wayland
      - network
    environment:
      QT_QPA_PLATFORM: wayland
      QT_PLUGIN_PATH: ${SNAP}/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/qt6/plugins/
      QT_QPA_PLATFORM_PLUGIN_PATH: ${SNAP}/usr/lib/${SNAPCRAFT_ARCH_TRIPLET}/qt6/plugins/platforms/

parts:
  qt-hello:
    source-type: git
    source: https://github.com/redacted.git
    plugin: cmake
    cmake-generator: Ninja
    ;; cmake-parameters:
    ;;   - -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt6/
    build-packages:
      - libgl1-mesa-dev
      - libvulkan-dev
      - libxkbcommon-dev
      - qt6-base-dev
      - qt6-tools-dev
      - qt6-l10n-tools

    stage-packages:
      - qt6-base-dev
      # not sure yet which ones I'll need

    stage-snaps:
      - ubuntu-frame

I can build and run the app on both Ubuntu and Windows using just cmake + ninja.

When using snapcraft it fails with

 Unpacking stage-snaps to /root/parts/qt-hello/install
 :: + cmake /root/parts/qt-hello/src -G Ninja
 :: -- Could NOT find Qt6LinguistTools (missing: Qt6LinguistTools_DIR)
 :: CMake Error at CMakeLists.txt:15 (find_package):
 ::   Found package configuration file:
 ::
 ::     /root/parts/qt-hello/install/usr/lib/x86_64-linux-gnu/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 "LinguistTools".
 ::
 ::   Expected Config file at
 ::   "/root/parts/qt-hello/install/usr/lib/x86_64-linux-gnu/cmake/Qt6LinguistTools/Qt6LinguistToolsConfig.cmake"
 ::   does NOT exist

When I enter the ldx container using snapcraft --debug I can confirm Qt6LinguistTools doesn’t exist in /root/parts/qt-hello/install/usr/lib/x86_64-linux-gnu/cmake/ but it does exist in /usr/lib/x86_64-linux-gnu/cmake/Qt6LinguistTools/Qt6LinguistToolsConfig.cmake.

What I don’t understand: the directory

/root/parts/qt-hello/install/usr/lib/x86_64-linux-gnu/cmake/ seems to be mirroring

/usr/lib/x86_64-linux-gnu/cmake/ but not quite, the latter contains 6 more Qt* directories - these are missing:

  • Qt6Designer
  • Qt6DesignerComponentsPrivate
  • Qt6Help
  • Qt6Linguist
  • Qt6Tools
  • Qt6ToolsTools
  • Qt6UiPlugin
  • Qt6UiTools

Next, I’ve tried to set

    cmake-parameters:
      - -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake/Qt6/

but got the same error message.

I can build it manually in the LXD container without any issues:

mkdir /root/parts/qt-hello/custom_build
cd /root/parts/qt-hello/custom_build
cmake -S /root/parts/qt-hello/src -B /root/parts/qt-hello/custom_build -G Ninja && ninja

– The CXX compiler identification is GNU 11.2.0 – Detecting CXX compiler ABI info – Detecting CXX compiler ABI info - done – Check for working CXX compiler: /usr/bin/c++ - skipped – Detecting CXX compile features – Detecting CXX compile features - done – Looking for C++ include pthread.h – Looking for C++ include pthread.h - found – Performing Test CMAKE_HAVE_LIBC_PTHREAD – Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success – Found Threads: TRUE
– Performing Test HAVE_STDATOMIC – Performing Test HAVE_STDATOMIC - Success – Found WrapAtomic: TRUE
– Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so
– Found WrapOpenGL: TRUE
– Found XKB: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (Required is at least version “0.5.0”) – Found WrapVulkanHeaders: /usr/include
– Configuring done – Generating done – Build files have been written to: /root/parts/qt-hello/custom_build

[0/2] Re-checking globbed directories… [8/8] Linking CXX executable qt-hello

There’s an example of building a Qt6 here:

Use this alongside the process described here:

I don’t know how you arrived at this recipe, but ubuntu-frame is not designed for use as a stage snap, so this is rather strange.

Hey Alan, thank you for the tips. I know your article and the iot-example-graphical-snap repository, it helped me start with ubuntu-frame. I could build the Qt6-example branch however the resulting snap (I assume it’s the Qt Quick Controls example shipped with Qt) is displaying rectangles instead of characters. It looks like this.

There are few points I do not understand in the example:

  • is it necessary to use a Personal Package Archives for installing Qt6? (ppa: daschuer/qt6-backports)
  • do I have to build the qtwayland from sources? Is the same as the official package called qt6-wayland-dev-tools?

I’ll remove ubuntu-frame stage snap (it was just a wild guess on my part that I needed it) and remove the QtLinguist dependency to see if I get further.

That sounds like an absence of fonts (or the font the application expects). These need to be included in the snap.

Snaps with base: core20 are based on the Ubuntu 20.04LTS archive, and that doesn’t contain Qt6. We will shortly be updating our examples to base: core22 when a PPA won’t be needed.

Sorry, I don’t know. But I would expect it to be called qt6-wayland (if it is in the PPA)