cmeson-buildflatpak

Can not run c code with meson and flatpak


The structure of the project is simple

.
├── main.c
├── meson.build
└── org.flatpak.myapp.json

main.c

#include <stdio.h>

int main() {
  printf("Hello World!");
  return 0;
}

meson.build

project('my-app', 'c')
executable('my-app', 'main.c')

org.flatpak.myapp.json

{
  "app-id": "org.flatpak.myapp",
  "runtime": "org.gnome.Platform",
  "runtime-version": "master",
  "sdk": "org.gnome.Sdk",
  "command": "my-app",
  "modules": [
    {
      "name": "my-app",
      "buildsystem": "meson",
      "sources": [
        {
          "type": "dir",
          "path": "."
        }
      ]
    }
  ]
}

I want to run the project with Flatpak and I use this command

flatpak-builder --user --install --force-clean build-dir org.flatpak.myapp.json 

Then got this error message

Error: Command 'my-app' not found

The complete output is

Downloading sources
Initializing build dir
Committing stage init to cache
Starting build of org.flatpak.myapp
========================================================================
Building module my-app in /home/azibom/Desktop/flatpack/.flatpak-builder/build/my-app-1
========================================================================
The Meson build system
Version: 1.2.1
Source dir: /run/build/my-app
Build dir: /run/build/my-app/_flatpak_build
Build type: native build
Project name: my-app
Project version: undefined
C compiler for the host machine: ccache cc (gcc 13.2.0 "cc (GCC) 13.2.0")
C linker for the host machine: cc ld.bfd 2.41
Host machine cpu family: x86_64
Host machine cpu: x86_64
Build targets in project: 1

my-app undefined

  User defined options
    prefix: /app

Found ninja-1.11.1 at /usr/bin/ninja
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.
[2/2] Linking target my-app
[0/1] Installing files.
Nothing to install.
Committing stage build-my-app to cache
Cleaning up
Committing stage cleanup to cache
Finishing app
Error: Command 'my-app' not found

Thanks


Solution

  • You need to make sure you actually install the "my-app" command inside your Flatpak runtime. If you add this in your meson.build, it should work

    project('my-app', 'c')
    executable('my-app', 'main.c',
      install: true,
    )