The Problem
I am currently studying app development with Vala using GTK and Libadwaita. As there are patterns I will need in many of my apps, I want to create a shared library. So I created a library and installed it via meson install
. The installation succeeded. Then, I added it as a dependency to an app project. The app project does not build as the dependency cannot be found.
The Code
The Library
I created a Meson library called "testlibrary". Here is the content of the /meson.build
file:
project(
'testlibrary',
['c', 'vala'],
version: '0.1.0',
meson_version: '>= 0.62.0',
default_options: [ 'warning_level=2', 'werror=false', ],
)
subdir('src')
pkgconfig = import('pkgconfig')
pkgconfig.generate(
version: '0.1.0',
name: 'testlibrary',
description: 'A test library.',
libraries: testlibrary
)
testlibrary
is defined under /src/meson.build
:
testlibrary_sources = [
'main.vala',
]
testlibrary_deps = [
dependency('glib-2.0'),
dependency('gobject-2.0'),
]
testlibrary = shared_library(
'testlibrary',
testlibrary_sources,
vala_args: '--target-glib=2.58',
dependencies: testlibrary_deps,
install: true
)
The Installation
Then I run the following commands:
meson build
cd build
sudo meson install
The output of the last command is:
ninja: Entering directory `/home/david-swift/Projects/testlibrary/build'
[3/3] Linking target src/libtestlibrary.so
Installing src/libtestlibrary.so to /usr/local/lib64
Installing /home/david-swift/Projects/testlibrary/build/meson-private/testlibrary.pc to /usr/local/lib64/pkgconfig
Now, I run pkg-config --libs testlibrary
for testing the installation and get:
-L/usr/local/lib64 -ltestlibrary
The testlibrary.pc
file is located under /usr/local/lib64/pkgconfig/
. It contains the following text:
prefix=/usr/local
includedir=${prefix}/include
libdir=${prefix}/lib64
Name: testlibrary
Description: A test library.
Version: 0.1.0
Libs: -L${libdir} -ltestlibrary
Cflags: -I${includedir}
The libtestlibrary.so
file is located under /usr/local/lib64/
.
There aren't any other files containing "testlibrary" in the file name on my system that are not in the project folder.
The App
So now, I add the library as a dependency to an app project called "sampleapp". That is the /src/meson.build
file:
sampleapp_sources = [
'main.vala',
'application.vala',
'window.vala',
]
sampleapp_deps = [
dependency('gtk4'),
dependency('libadwaita-1', version: '>= 1.2'),
dependency('testlibrary', version: '>=0.1.0')
]
sampleapp_sources += gnome.compile_resources(
'sampleapp-resources',
'sampleapp.gresource.xml',
c_name: 'sampleapp'
)
executable(
'sampleapp',
sampleapp_sources,
dependencies: sampleapp_deps,
install: true
)
When I build the app using meson build
, it fails as the dependency "testlibrary" cannot be found, tried pkgconfig and cmake. Here is the full log:
Build started at 2023-06-03T06:27:02.510652
Main binary: /usr/bin/python3
Build Options: -Dprefix=/app -Dbackend=ninja
Python system: Linux
The Meson build system
Version: 0.63.3
Source dir: /home/david-swift/Projects/SampleApp
Build dir: /home/david-swift/.cache/gnome-builder/projects/SampleApp/builds/ch.david_swift.SampleApp.json-flatpak-org.gnome.Platform-master-x86_64-main
Build type: native build
Project name: sampleapp
Project version: 0.1.0
C compiler for the host machine: ccache cc (gcc 12.2.0 "cc (GCC) 12.2.0")
C linker for the host machine: cc ld.bfd 2.38
Vala compiler for the host machine: valac (valac 0.57.0.129-1da850)
C compiler for the build machine: ccache cc (gcc 12.2.0 "cc (GCC) 12.2.0")
C linker for the build machine: cc ld.bfd 2.38
Vala compiler for the build machine: valac (valac 0.57.0.129-1da850)
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
Program msgfmt found: YES (/usr/bin/msgfmt)
Program desktop-file-validate found: YES (/usr/bin/desktop-file-validate)
Adding test "Validate desktop file"
Program appstream-util found: YES (/usr/bin/appstream-util)
Adding test "Validate appstream file"
Program glib-compile-schemas found: YES (/usr/bin/glib-compile-schemas)
Adding test "Validate schema file"
Dependency gtk4 found: YES 4.11.2 (cached)
Dependency libadwaita-1 found: YES 1.4.alpha (cached)
Pkg-config binary for 1 is not cached.
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: /usr/bin/pkg-config (1.8.0)
Determining dependency 'testlibrary' with pkg-config executable '/usr/bin/pkg-config'
env[PKG_CONFIG_PATH]: /app/lib/pkgconfig:/app/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig
Called `/usr/bin/pkg-config --modversion testlibrary` -> 1
CMake binary for 1 is not cached
CMake binary missing from cross or native file, or env var undefined.
Trying a default CMake fallback at cmake
Found CMake: /usr/bin/cmake (3.25.2)
Extracting basic cmake information
CMake Toolchain: Calling CMake once to generate the compiler state
Calling CMake (['/usr/bin/cmake']) in /home/david-swift/.cache/gnome-builder/projects/SampleApp/builds/ch.david_swift.SampleApp.json-flatpak-org.gnome.Platform-master-x86_64-main/meson-private/__CMake_compiler_info__ with:
- "--trace-expand"
- "--trace-format=json-v1"
- "--no-warn-unused-cli"
- "--trace-redirect=cmake_trace.txt"
- "-G"
- "Ninja"
- "-DCMAKE_TOOLCHAIN_FILE=/home/david-swift/.cache/gnome-builder/projects/SampleApp/builds/ch.david_swift.SampleApp.json-flatpak-org.gnome.Platform-master-x86_64-main/meson-private/__CMake_compiler_info__/CMakeMesonTempToolchainFile.cmake"
- "."
WARNING: CMake Toolchain: Failed to determine CMake compilers state
Try CMake generator: auto
Calling CMake (['/usr/bin/cmake']) in /home/david-swift/.cache/gnome-builder/projects/SampleApp/builds/ch.david_swift.SampleApp.json-flatpak-org.gnome.Platform-master-x86_64-main/meson-private/cmake_testlibrary with:
- "--trace-expand"
- "--trace-format=json-v1"
- "--no-warn-unused-cli"
- "--trace-redirect=cmake_trace.txt"
- "-DCMAKE_TOOLCHAIN_FILE=/home/david-swift/.cache/gnome-builder/projects/SampleApp/builds/ch.david_swift.SampleApp.json-flatpak-org.gnome.Platform-master-x86_64-main/meson-private/cmake_testlibrary/CMakeMesonToolchainFile.cmake"
- "."
-- Module search paths: ['/', '/usr']
-- CMake root: /usr/share/cmake-3.25
-- CMake architectures: ['aarch64-linux-gnu', 'arm-linux-gnueabihf', 'i386-linux-gnu', 'x86_64-linux-gnu']
-- CMake lib search paths: ['lib', 'lib32', 'lib64', 'libx32', 'share', 'lib/aarch64-linux-gnu', 'lib/arm-linux-gnueabihf', 'lib/i386-linux-gnu', 'lib/x86_64-linux-gnu']
Preliminary CMake check failed. Aborting.
Run-time dependency testlibrary found: NO (tried pkgconfig and cmake)
../../../../../../Projects/SampleApp/src/meson.build:7:0: ERROR: Dependency "testlibrary" not found, tried pkgconfig and cmake
What I Tried
As this comment suggests, I tried moving the contents of /usr/local/lib64
to /etc/ld.so.conf.d
. The app did not build and it would not have been an elegant solution to the problem: I want the library to be directly usable after running meson install
.