Bulder fails with meson error (can't find gtkmm)

I’m trying to run a Hello World with C++ and GTK4, but when I try to build it Meson doesn’t find the gtkmm-4.0 library.

I’ve followed the gtkmm documentation, installed the library and pkg-config and was able to build it using g++ simple.cc -o simple 'pkg-config --cflags --libs gtkmm-4.0' -std=c++17 as specified in the documentation.

But when I tried to build it in Builder, Meson isn’t able to find the library.

I’ve followed the instructions here to add the dependency to meson.build.

Here’s my meson.build file inside /src:

hello_sources = [
  'main.cpp',
]

hello_deps = [dependency('gtkmm-4.0')
]

executable('hello', hello_sources,
  dependencies: hello_deps,
  install: true,
)

and my main.cpp:

#include <gtkmm.h>

class MyWindow : public Gtk::Window
{
public:
  MyWindow();
};

MyWindow::MyWindow()
{
  set_title("Basic application");
  set_default_size(200, 200);
}

int main(int argc, char* argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.examples.base");

  return app->make_window_and_run<MyWindow>(argc, argv);
}

The logs resulted from the failed build:

-----------
C++ compiler for the build machine: ccache c++ (gcc 13.2.0 "c++ (GCC) 13.2.0")
C++ linker for the build machine: c++ ld.bfd 2.43.1
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: x86_64
Host machine cpu: x86_64
Target machine cpu family: x86_64
Target machine cpu: x86_64
Pkg-config binary missing from cross or native file, or env var undefined.
Trying a default Pkg-config fallback at pkg-config
Found pkg-config: YES (/usr/bin/pkg-config) 2.3.0
Determining dependency 'gtkmm-4.0' with pkg-config executable '/usr/bin/pkg-config'
env[PKG_CONFIG_PATH]: /app/lib/pkgconfig:/app/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
env[PKG_CONFIG]: /usr/bin/pkg-config
-----------
Called: `/usr/bin/pkg-config --modversion gtkmm-4.0` -> 1
stderr:
Package gtkmm-4.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-4.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gtkmm-4.0' not found

Could somebody help me find the mistake and understand why is Meson trying to find the library with --modversion ? Thanks ^^

I think this needs adding a "project" entry to meson.build.

What’s the output of the following command in you source dir ?

$ meson setup _build
The Meson build system
Version: 1.6.0
Source dir: /home/salguento/Projects/Hello
Build dir: /home/salguento/Projects/Hello/setup_build
Build type: native build
Project name: hello
Project version: 0.1.0
C compiler for the host machine: cc (gcc 14.2.1 "cc (GCC) 14.2.1 20240910")
C linker for the host machine: cc ld.bfd 2.43.0
C++ compiler for the host machine: c++ (gcc 14.2.1 "c++ (GCC) 14.2.1 20240910")
C++ linker for the host machine: c++ ld.bfd 2.43.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: YES (/usr/bin/pkg-config) 2.1.1
Run-time dependency gtkmm-4.0 found: YES 4.16.0
Build targets in project: 1

Found ninja-1.12.1 at /usr/bin/ninja
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.

It appears you’re using the wrong runtime for building in GNOME Builder.

  1. Press Alt + , to open project configuration dialog.
  2. Check if runtime is set to Host Operating System (as shown below).

It’s set to Host Operating System

Try selecting Default in Active Configuration as shown below and try building it.

builder-project-config-1

It worked! Thanks for the time and help :smile:

Same way if you want to build a flatpak version of your app, you should include the proper dependencies in .json manifest (e.g. com.example.Hello.json) and choose that in the Active Configuration.

1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.