0

Due to my laziness, I have downloaded precompiled binaries for GTK programmes (rather than compiling them which would have been a drag considering how time-wasting it is). EDIT:using sudo apt get, meaning it should probably be compatible

I have downloaded a few of them, I think. I did download one with "-dev" label and the one without.

The programme I've tried executing was from "GeeksForGeeks" if I recall correctly.

#include <gtk/gtk.h>
static int counter = 0;

void greet(GtkWidget* widget, gpointer data)
{
    // printf equivalent in GTK+
    g_print("Welcome to GTK\n");
    g_print("%s clicked %d times\n",
            (char*)data, ++counter);
}

void destroy(GtkWidget* widget, gpointer data)
{
    gtk_main_quit();
}

int main(int argc, char* argv[])
{

    GtkWidget* window;
    GtkWidget* button;
    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    g_signal_connect(window, "destroy",
                    G_CALLBACK(destroy), NULL);
    /* Let's set the border width of the window to 20.
    * You may play with the value and see the
    * difference. */
    gtk_container_set_border_width(GTK_CONTAINER(window), 20);

    button = gtk_button_new_with_label("Click Me!");

    g_signal_connect(GTK_OBJECT(button),
                    "clicked", G_CALLBACK(greet),
                    "button");

    gtk_container_add(GTK_CONTAINER(window), button);

    gtk_widget_show_all(window);

    gtk_main();

    return 0;
}

But right after copy-pasting it onto micro, before I saved it, I was met with error mentioning that there is no such directory such as gtk/gtk.h.

I then proceeded to link the exact location of gtk.h.

That one met me with an another error: gio.h

I've tried google searching, but none of the results give me a working answer. I too hope this question is relevant to unix stackexchange as it's one on the subject of programming. The reason I am posting it in here is because it's mostly a problem closely connected to linux/unix system, rather than the code. The code is perfectly fine as to my knowledge.

P.S. As one can see in the screenshot, I did try linking the library and other stuff

1 Answer 1

2

You need to sudo apt install libgtk-3-dev

then compile it with options obtained from pkg-config:

gcc $(pkg-config --cflags gtk+-3.0) $(pkg-config --libs gtk+-3.0) -o prog program.c

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .