Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 23/12/2007, à 01:03

thanorval

librairie gtk en C ?

Bonjour,
j'essaie d'inclure la librairie gtk en C sous KDE (j'utilise Kubuntu 7.10). Mais même un exemple simple ne donne rien. J'obtiens "error: gtk/gtk.h: No such file or directory". Pourtant tout semble installé (libgtk1.2). Quel est le B.A.BA de la programmation avec gtk ? Voici le mini programme
// combo.c
// exemple de combobox en gtk+ (liste deroulante)

#include <stdio.h>
#include <gtk/gtk.h>



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

    GtkWidget *Dialogue, *Combo, *Bouton;
    GList *list = NULL;
    gint i;

    gtk_init(&argc, &argv);

    Dialogue = gtk_dialog_new();
    gtk_window_set_title(GTK_WINDOW(Dialogue), "Exemple de combo box");

    gtk_widget_show(Dialogue);

    for(i=0; i<10; i++)
        list = g_list_append(list, g_strdup_printf("chaine %d", i)); // ajoute une chaine a le liste


    Combo = gtk_combo_new(); // cree une liste deroulante
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)->vbox), Combo, TRUE, TRUE, 0);
    gtk_combo_set_popdown_strings( GTK_COMBO(Combo), list) ; // met la liste dans la conbo box
    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(Combo)->entry), "coucou"); // definit le texte de la conbo box


    gtk_widget_show(Combo);

    Bouton = gtk_button_new_with_label("Fermer");
    gtk_signal_connect_object(GTK_OBJECT(Bouton), "clicked", (GtkSignalFunc)gtk_exit, NULL);
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)->action_area), Bouton , TRUE, TRUE, 0);

    gtk_widget_show(Bouton);

    gtk_main();

    return(0);
}

voici la réponse du compilateur (gcc) :

/home/snicolay/cpp/gtk.c:5:21: error: gtk/gtk.h: No such file or directory
/home/snicolay/cpp/gtk.c: In function ‘main’:
/home/snicolay/cpp/gtk.c:12: error: ‘GtkWidget’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:12: error: (Each undeclared identifier is reported only once
/home/snicolay/cpp/gtk.c:12: error: for each function it appears in.)
/home/snicolay/cpp/gtk.c:12: error: ‘Dialogue’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:12: error: ‘Combo’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:12: error: ‘Bouton’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:13: error: ‘GList’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:13: error: ‘list’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:14: error: ‘gint’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:14: error: expected ‘;’ before ‘i’
/home/snicolay/cpp/gtk.c:23: error: ‘i’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:28: error: invalid type argument of ‘->’
/home/snicolay/cpp/gtk.c:28: error: ‘TRUE’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:30: error: invalid type argument of ‘->’
/home/snicolay/cpp/gtk.c:36: error: ‘GtkSignalFunc’ undeclared (first use in this function)
/home/snicolay/cpp/gtk.c:36: error: expected ‘)’ before ‘gtk_exit’
/home/snicolay/cpp/gtk.c:37: error: invalid type argument of ‘->’


D'avance merci pour votre aide et désolé pour la question peut être naà¯ve.

#2 Le 23/12/2007, à 02:09

Link31

Re : librairie gtk en C ?

Hors ligne

#3 Le 23/12/2007, à 13:38

GarulfoUnix

Re : librairie gtk en C ?

je dirai plutôt :

sudo apt-get install libgtk2.0-dev

A quoi bon de programmer avec la v1.2 de Gtk? wink


http://doc.ubuntu-fr.org/gambas - Documentation sur le wiki
http://gambas.shos.fr - Site de la communauté francophone des utilisateurs de Gambas

Hors ligne

#4 Le 23/12/2007, à 20:43

trucutu_

Re : librairie gtk en C ?

Et puis, quelle est la commande de compilation utilisée ?
Est-elle bonne ?

#5 Le 26/12/2007, à 10:10

Karl_le_rouge

Re : librairie gtk en C ?

$ cc -o combo combo.c `pkg-config gtk+ --cflags --libs` # gtk 1.2
$ cc -o combo combo.c `pkg-config gtk+-2.0 --cflags --libs` # gtk 2.x

Ton code compile avec Gtk+ 2.0
Passe à Gtk+ 2.0 et arrête de piquer tes yeux avec cette antiquité de Gtk+ 1.2 !

Hors ligne