Search code examples
linuxrustgtkpkg-config

Where is the `glib-2.0` file on Linux?


I have a simple Gtk app in Rust, but I get this error when compiling:

Package glib-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `glib-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'glib-2.0' found

And yes, I read Cannot compile gstreamer on Windows because it is missing glib-2.0, but it still doesn't contain all the information I need.

I put export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig/ in /home/user/.profile (as shown in Can't Set Environment Variables in ~/.profile), and I also ran it directly in the Rust project directory, to no avail. I used that path because it seemed closest to the one in the Windows question, though there were many pkgconfig directories on the system, in various places.

Here is my Rust code:

use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};

fn main() {
    let app = Application::builder()
        .application_id("org.example.HelloWorld")
        .build();

    app.connect_activate(|app| {
        // We create the main window.
        let window = ApplicationWindow::builder()
            .application(app)
            .default_width(320)
            .default_height(200)
            .title("Hello, World!")
            .build();

        // Show the window.
        window.show();
    });

    app.run();
}

and here is Cargo.toml:

[package]
name = "gtk_test"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
gtk = { version = "0.2", package = "gtk4" }

So my question: where is the glib-2.0.pc file on a Linux? Is it under a different name, or does it have to be installed?


Solution

  • I've had the same issue on Fedora 36 ARM. I've installed libwebkitgtk, rust-gtk-sys-devel, libproxy-webkitgtk4, webkitgtk4, libsoup, libsoup-devel and webkitgtk4-devel and it started working. Some of libraries above may not be needed for your issue. For fedora the command is:

    sudo dnf install libwebkitgtk rust-gtk-sys-devel libproxy-webkitgtk4 webkitgtk4 libsoup libsoup-devel webkitgtk4-devel