0

I am building an application that includes gtk and libhandy libraries. I am trying to bundle libhandy to my project. I am using the meson build system. To add the dependency to meson I have followed the following documentation from here 1

I have cloned the libhandy library into my project to project_root/subprojects/libhandy/ Here is my project_root/meson.build file

project('githandytest', 'c',
          version: '0.1.0',
    meson_version: '>= 0.50.0',
  default_options: [ 'warning_level=2',
                     'c_std=gnu11',
                   ],
)

libhandy_dep = dependency('libhandy-0.0', version: '>= 0.0.13')
if not libhandy_dep.found()
  libhandy = subproject(
    'libhandy',
    install: false,
    default_options: [
      'examples=false',
      'package_subdir=my-project-name',
      'tests=false',
    ]
  )
  libhandy_dep = libhandy.get_variable('libhandy_dep')
endif

i18n = import('i18n')

config_h = configuration_data()
config_h.set_quoted('PACKAGE_VERSION', meson.project_version())
config_h.set_quoted('GETTEXT_PACKAGE', 'githandytest')
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
configure_file(
  output: 'githandytest-config.h',
  configuration: config_h,
)
add_project_arguments([
  '-I' + meson.build_root(),
], language: 'c')


subdir('data')
subdir('src')
subdir('po')
subdir('subprojects')

meson.add_install_script('build-aux/meson/postinstall.py')

The file in which I am including <libhandy.h> is main.c located in project_root/src Here is project_root/src/meson.build

githandytest_sources = [
  'main.c'
]

githandytest_deps = [
  dependency('gio-2.0', version: '>= 2.50'),
  dependency('gtk+-3.0', version: '>= 3.22'),
  dependency('libhandy-0.0')
]

gnome = import('gnome')

executable('githandytest', githandytest_sources,
  dependencies: githandytest_deps,
  install: true,
)

I have also added sources to the project manifest since I am distributing with flatpak.

{
    "app-id" : "org.example.App",
    "runtime" : "org.gnome.Platform",
    "runtime-version" : "3.38",
    "sdk" : "org.gnome.Sdk",
    "command" : "githandytest",
    "finish-args" : [
        "--share=network",
        "--share=ipc",
        "--socket=fallback-x11",
        "--socket=wayland"
    ],
    "cleanup" : [
        "/include",
        "/lib/pkgconfig",
        "/man",
        "/share/doc",
        "/share/gtk-doc",
        "/share/man",
        "/share/pkgconfig",
        "*.la",
        "*.a"
    ],
    "modules" : [
        {
            "name" : "githandytest",
            "builddir" : true,
            "buildsystem" : "meson",
            "sources" : [
                {
                    "type" : "git",
                    "url" : "file:///home/davtyan/Projects/githandytest"
                }
            ]
        },
        {
      "name" : "libhandy",
      "buildsystem" : "meson",
      "builddir" : true,
      "config-opts": [
        "-Dexamples=false",
        "-Dtests=false"
      ],
      "sources" : [
        {
          "type" : "git",
          "url" : "https://source.puri.sm/Librem5/libhandy.git"
        }
      ]
    }
    ]
}

The issue I get when running the project is: project_root/meson.build:9:0: ERROR: Dependency "libhandy-0.0" not found, tried pkgconfig and cmake

I apologize for such a vague question. I am very new to the meson build system and can't quite figure why this happens. I am using the gnome-builder IDE if that helps.

Vahan
  • 166
  • 13

1 Answers1

1

It looks that you don't need to create dependency object for the second time dependency('libhandy-0.0') and use already created:

githandytest_deps = [
  dependency('gio-2.0', version: '>= 2.50'),
  dependency('gtk+-3.0', version: '>= 3.22'),
  libhandy_dep
]

I mean you have this error because it tries to find (using pkg-config) this dependency not looking at your evaluation of libhandy_dep.

However, note that the evaluation of this dependency (pkg-config + subproject) can be simplified with just:

libhandy_dep = dependency('libhandy-0.0', version: '>= 0.0.13', 
             fallback : ['libhandy', 'libhandy_dep'],
             default_options: ['examples=false', 'package_subdir=my-project-name', 'tests=false'])

since from docs:

['subproj_name', 'subproj_dep'], the first value is the name of the subproject and the second is the variable name in that subproject that contains a dependency object such as the return value of declare_dependency or dependency(),

pmod
  • 10,450
  • 1
  • 37
  • 50
  • Thanks a lot this solved the issue. However I am now stuck with another issue. When I inlcude and compile my source file, it works fine. But whenever I call any function or object defined in it shows the following error: error while loading shared libraries: libhandy-1.so.0: cannot open shared object file: No such file or directory – Vahan Dec 25 '20 at 14:02
  • @Vahan it happens because shared library is built to some unknown folder for runtime loader, try set "build_rpath" option for executable. I am not sure where it should land ... probably you try to add : executable(...., build_rpath : current_build_dir() + '/libhandy' ...) but it's just my wild guess – pmod Dec 25 '20 at 23:49
  • maybe this can help also https://stackoverflow.com/questions/61058722/how-can-i-specify-library-path-when-using-meson – pmod Dec 25 '20 at 23:52