Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Cargo can't find installed Gtk libraries
I'm trying to build a Rust program that uses Gtk4, specifically riff, but I think any Rust program that depends on Gtk4 will reproduce this error. However, Cargo keeps complaining that various Gtk-related libraries don't exist. Here is the output of the compiler:
Compiling openssl-sys v0.9.109
Compiling glib-sys v0.20.10
Compiling gobject-sys v0.20.10
Compiling gio-sys v0.20.10
Compiling glib-sys v0.21.1
Compiling gobject-sys v0.21.1
warning: [email protected]:
error: failed to run custom build command for `glib-sys v0.20.10`
Caused by:
process didn't exit successfully: `/home/user/.local/share/riff/target/release/build/glib-sys-4792b6431b7a0065/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-changed=/home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glib-sys-0.20.10/Cargo.toml
cargo:rerun-if-env-changed=GLIB_2.0_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:warning=
pkg-config exited with status code 1
> PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags glib-2.0 'glib-2.0 >= 2.82'
The system library `glib-2.0` required by crate `glib-sys` was not found.
The file `glib-2.0.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
PKG_CONFIG_PATH contains the following:
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
HINT: you may need to install a package such as glib-2.0, glib-2.0-dev or glib-2.0-devel.
warning: build failed, waiting for other jobs to finish...
warning: [email protected]:
error: failed to run custom build command for `gobject-sys v0.20.10`
Caused by:
process didn't exit successfully: `/home/user/.local/share/riff/target/release/build/gobject-sys-6bd21c007fde8ecd/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-changed=/home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gobject-sys-0.20.10/Cargo.toml
cargo:rerun-if-env-changed=GOBJECT_2.0_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:warning=
pkg-config exited with status code 1
> PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags gobject-2.0 'gobject-2.0 >= 2.82'
The system library `gobject-2.0` required by crate `gobject-sys` was not found.
The file `gobject-2.0.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
PKG_CONFIG_PATH contains the following:
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
HINT: you may need to install a package such as gobject-2.0, gobject-2.0-dev or gobject-2.0-devel.
warning: [email protected]:
error: failed to run custom build command for `gio-sys v0.20.10`
Caused by:
process didn't exit successfully: `/home/user/.local/share/riff/target/release/build/gio-sys-2bcfe94ddf82bd0d/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-changed=/home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gio-sys-0.20.10/Cargo.toml
cargo:rerun-if-env-changed=GIO_2.0_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
cargo:warning=
pkg-config exited with status code 1
> PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags gio-2.0 'gio-2.0 >= 2.82'
The system library `gio-2.0` required by crate `gio-sys` was not found.
The file `gio-2.0.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
PKG_CONFIG_PATH contains the following:
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
- /usr/lib/x86_64-linux-gnu/pkgconfig
HINT: you may need to install a package such as gio-2.0, gio-2.0-dev or gio-2.0-devel.
However, even though I've added the directory containing these files to the PKG_CONFIG_PATH environment variable and installed what seems like every Gtk library known to mankind, it still throws these errors.
This is a problem I come across once every year or so, when I get back into Rust Gtk development, but by the time it happens again, I've long forgotten how I solved it before.
This is the output when I run ls /usr/lib/x86_64-linux-gnu/pkgconfig/. You can see that some of the very libraries Cargo is complaining about are in this directory.
alsa.pc gdk-pixbuf-xlib-2.0.pc gstreamer-gl-prototypes-1.0.pc gudev-1.0.pc libmpg123.pc orc-0.4.pc sqlite3.pc
atk-bridge-2.0.pc gdk-wayland-3.0.pc gstreamer-gl-wayland-1.0.pc harfbuzz-cairo.pc libout123.pc orc-test-0.4.pc tbb.pc
atk.pc gdk-x11-3.0.pc gstreamer-gl-x11-1.0.pc harfbuzz-gobject.pc libpcre2-16.pc pangocairo.pc uuid.pc
atspi-2.pc geoclue-2.0.pc gstreamer-insertbin-1.0.pc harfbuzz-icu.pc libpcre2-32.pc pangofc.pc vorbisenc.pc
blkid.pc gio-2.0.pc gstreamer-mpegts-1.0.pc harfbuzz.pc libpcre2-8.pc pangoft2.pc vorbisfile.pc
cairo-fc.pc giomm-2.4.pc gstreamer-mse-1.0.pc harfbuzz-subset.pc libpcre2-posix.pc pangomm-2.48.pc vorbis.pc
cairo-ft.pc giomm-2.68.pc gstreamer-net-1.0.pc ibus-1.0.pc libpng16.pc pangoot.pc vulkan.pc
cairo-gobject.pc gio-qt.pc gstreamer-pbutils-1.0.pc ice.pc libpng.pc pango.pc wayland-client.pc
cairomm-1.16.pc gio-unix-2.0.pc gstreamer-photography-1.0.pc icu-i18n.pc libpulse-mainloop-glib.pc pangoxft.pc wayland-cursor.pc
cairomm-ft-1.16.pc glesv1_cm.pc gstreamer-play-1.0.pc icu-io.pc libpulse.pc pciaccess.pc wayland-egl.pc
cairomm-pdf-1.16.pc glesv2.pc gstreamer-player-1.0.pc icu-uc.pc libpulse-simple.pc pixman-1.pc wayland-server.pc
cairomm-png-1.16.pc glib-2.0.pc gstreamer-plugins-bad-1.0.pc Imath.pc libraw1394.pc pthread-stubs.pc x11.pc
cairomm-ps-1.16.pc glibmm-2.4.pc gstreamer-plugins-base-1.0.pc jack.pc libselinux.pc PyImath.pc x11-xcb.pc
cairomm-svg-1.16.pc glibmm-2.68.pc gstreamer-plugins-good-1.0.pc jsoncpp.pc libsepol.pc python-3.12-embed.pc xau.pc
cairomm-xlib-1.16.pc gl.pc gstreamer-riff-1.0.pc Lerc.pc libsharpyuv.pc python-3.12.pc xcb.pc
cairomm-xlib-xrender-1.16.pc glx.pc gstreamer-rtp-1.0.pc libavcodec.pc libssl.pc python3-embed.pc xcb-render.pc
cairo.pc gmodule-2.0.pc gstreamer-rtsp-1.0.pc libavformat.pc libswresample.pc python3.pc xcb-shape.pc
cairo-pdf.pc gmodule-export-2.0.pc gstreamer-sctp-1.0.pc libavutil.pc libswscale.pc Qt6Concurrent.pc xcb-shm.pc
cairo-png.pc gmodule-no-export-2.0.pc gstreamer-sdp-1.0.pc libbrotlicommon.pc libsyn123.pc Qt6Core.pc xcb-xfixes.pc
cairo-ps.pc gmp.pc gstreamer-tag-1.0.pc libbrotlidec.pc libthai.pc Qt6DBus.pc xcomposite.pc
cairo-script-interpreter.pc gmpxx.pc gstreamer-transcoder-1.0.pc libbrotlienc.pc libtiff-4.pc Qt6Gui.pc xcursor.pc
cairo-script.pc gobject-2.0.pc gstreamer-va-1.0.pc libcrypto.pc libudev.pc Qt6Network.pc xdamage.pc
cairo-svg.pc gobject-introspection-1.0.pc gstreamer-video-1.0.pc libcrypt.pc libunwind-coredump.pc Qt6OpenGL.pc xdmcp.pc
cairo-tee.pc gobject-introspection-no-export-1.0.pc gstreamer-vulkan-1.0.pc libcurl.pc libunwind-generic.pc Qt6OpenGLWidgets.pc xext.pc
cairo-xcb.pc graphene-1.0.pc gstreamer-vulkan-wayland-1.0.pc libdc1394-2.pc libunwind.pc Qt6Platform.pc xfixes.pc
cairo-xcb-shm.pc graphene-gobject-1.0.pc gstreamer-vulkan-xcb-1.0.pc libdecor-0.pc libunwind-ptrace.pc Qt6PrintSupport.pc xft.pc
cairo-xlib.pc graphite2.pc gstreamer-wayland-1.0.pc libdeflate.pc libwebpdecoder.pc Qt6Sql.pc xinerama.pc
cairo-xlib-xrender.pc grilo-plugins-0.3.pc gstreamer-webrtc-1.0.pc libdrm_amdgpu.pc libwebpdemux.pc Qt6Svg.pc xi.pc
datrie-0.2.pc gstreamer-1.0.pc gstreamer-webrtc-nice-1.0.pc libdrm_intel.pc libwebpmux.pc Qt6SvgWidgets.pc xkbcommon.pc
dbus-1.pc gstreamer-allocators-1.0.pc gthread-2.0.pc libdrm_nouveau.pc libwebp.pc Qt6Test.pc xmu.pc
egl.pc gstreamer-analytics-1.0.pc gtk+-3.0.pc libdrm.pc libxcrypt.pc Qt6Widgets.pc xorg-wacom.pc
epoxy.pc gstreamer-app-1.0.pc gtk4-atspi.pc libdrm_radeon.pc libzstd.pc Qt6Xml.pc xrandr.pc
expat.pc gstreamer-audio-1.0.pc gtk4-broadway.pc libdw.pc luajit.pc rtaudio.pc xrender.pc
flac.pc gstreamer-bad-audio-1.0.pc gtk4.pc libelf.pc mount.pc rtmidi.pc xscrnsaver.pc
fontconfig.pc gstreamer-base-1.0.pc gtk4-unix-print.pc libevdev.pc numpy.pc samplerate.pc xt.pc
freetype2.pc gstreamer-check-1.0.pc gtk4-wayland.pc libexif.pc ogg.pc sdl2.pc xtst.pc
fribidi.pc gstreamer-codecparsers-1.0.pc gtk4-x11.pc libffi.pc openal.pc sigc++-2.0.pc xv.pc
fuse.pc gstreamer-controller-1.0.pc gtk+-broadway-3.0.pc libglvnd.pc opencv4.pc sigc++-3.0.pc xwayland.pc
gbm.pc gstreamer-cuda-1.0.pc gtkmm-4.0.pc libgphoto2.pc OpenEXR.pc sm.pc xxf86vm.pc
gdk-3.0.pc gstreamer-fft-1.0.pc gtk+-unix-print-3.0.pc libgphoto2_port.pc opengl.pc sndfile.pc z3.pc
gdk-broadway-3.0.pc gstreamer-gl-1.0.pc gtk+-wayland-3.0.pc libjpeg.pc openssl.pc sndio.pc zlib.pc
gdk-pixbuf-2.0.pc gstreamer-gl-egl-1.0.pc gtk+-x11-3.0.pc liblzma.pc opus.pc speech-dispatcher.pc
How would I go about fixing this problem? I'm using Rust 1.89.0 on Ubuntu 24.04.2 LTS.
1 answer
The following users marked this post as Works for me:
| User | Comment | Date |
|---|---|---|
| Sylvester | (no comment) | Sep 3, 2025 at 17:10 |
It turns out that jmb's comment was correct; my version of gio was too old.
After being led by Virgil through the nine circles of dependency hell, I eventually just upgraded to Ubuntu 25. Unfortunately I don't remember whether I then had to manually install the newer version of gio or not, since there were lots of things I had to fix to get the new Ubuntu version working, and even then the upgrade is still a tiny bit broken in places.
The latest versions of the gtk4 Rust library require a gio version of 2.82 or newer, so you can use this command (as suggested in jmb's comment) to check whether you have the correct version:
pkg-config --libs --cflags gio-2.0 'gio-2.0 >= 2.82'
If you don't have the right version, you'll get a message something like this:
Package dependency requirement 'gio-2.0 >= 2.82' could not be satisfied.
Package 'gio-2.0' has version '2.53.1', required version is '>= 2.82'

1 comment thread