Installer gtk+ sous Linux

Résolu
Technoinfo Messages postés 362 Date d'inscription jeudi 6 octobre 2016 Statut Membre Dernière intervention 17 avril 2021 - Modifié le 23 mars 2017 à 18:46
Technoinfo Messages postés 362 Date d'inscription jeudi 6 octobre 2016 Statut Membre Dernière intervention 17 avril 2021 - 25 mars 2017 à 18:06
Bonjour.
Je viens d'installer gtk3 en suivant ce tutoriel :https://openclassrooms.com/courses/creez-une-interface-avec-gtk/installer-gtk-sous-linux en prenant le soin de remplacer les paquets de gtk2 par ceux de gtk3.
J'ai utilisés les paquets
libgtk-3-dev
et
libgtk-3-0
au lieu de
libgtk2.0-dev
et
libgtk2.0-0
et quand je tente de compiler avec cette ligne de commande :
gcc $(pkg-config --libs --cflags gtk+-3.0) main.c -o test

Voila le résultat :https://framapic.org/wZedcbTQglxj/CbTStiLoouK7?t=
J'espere que vous pourrez m'aider.
Cordialement.
Technoinfo.
P.S:Je supprimerai l'image des que le sujet sera résolu

Linux+Windows=Dual boot
A voir également:

7 réponses

cptpingu Messages postés 3837 Date d'inscription dimanche 12 décembre 2004 Statut Modérateur Dernière intervention 28 mars 2023 123
Modifié le 25 mars 2017 à 15:44
Au vu de la réponse, je ne vois rien de choquant. J'ai donc installé Linux Mint 17.3 dans une VM, et j'ai installé gtk via:
sudo aptitude install libgtk-3-dev


Puis j'ai pris l'exemple suivant (gtk3, tu as du prendre un exemple gtk2):
#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  gtk_widget_show_all (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}


Que j'ai compilé comme tu l'as indiqué:
gcc $(pkg-config --libs --cflags gtk+-3.0) main.c -o test


Et effectivement, je reproduis l'erreur:
/tmp/ccKHhhbK.o: In function `activate':
main.c:(.text+0x18): undefined reference to `gtk_application_window_new'
main.c:(.text+0x21): undefined reference to `gtk_window_get_type'
main.c:(.text+0x33): undefined reference to `g_type_check_instance_cast'
main.c:(.text+0x40): undefined reference to `gtk_window_set_title'
main.c:(.text+0x45): undefined reference to `gtk_window_get_type'
main.c:(.text+0x57): undefined reference to `g_type_check_instance_cast'
main.c:(.text+0x69): undefined reference to `gtk_window_set_default_size'
main.c:(.text+0x75): undefined reference to `gtk_widget_show_all'
/tmp/ccKHhhbK.o: In function `main':
main.c:(.text+0x95): undefined reference to `gtk_application_new'
main.c:(.text+0xc0): undefined reference to `g_signal_connect_data'
main.c:(.text+0xc5): undefined reference to `g_application_get_type'
main.c:(.text+0xd7): undefined reference to `g_type_check_instance_cast'
main.c:(.text+0xe8): undefined reference to `g_application_run'
main.c:(.text+0xf7): undefined reference to `g_object_unref'
collect2: error: ld returned 1 exit status


En lisant la doc, j'ai trouvé le souci :). C'est super vicieux, mais dans les nouvelles versions de gcc, il faut bien séparer la déclaration des flags et du link. Le link doit forcément être à la fin ! Le tuto que tu utilises est trop vieux, tout simplement :). Donc la bonne commande est:
gcc $(pkg-config --cflags gtk+-3.0) main.c -o test $(pkg-config --libs gtk+-3.0)


Et ça fonctionne ! Bien faire attention à l'ordre.

Améliorer votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature
2
cptpingu Messages postés 3837 Date d'inscription dimanche 12 décembre 2004 Statut Modérateur Dernière intervention 28 mars 2023 123
Modifié le 23 mars 2017 à 19:34
Bonjour.

Est-ce normal que la ligne présentée ici soit différente de celle de la capture d'écran ?
Que renvoie la commande "pkg-config --libs --cflags gtk+-3.0" ?

Edit: Il y a marqué gtk+-230 ce qui me paraît suspect.


Améliorer votre expérience CodeS-SourceS avec ce plugin:
http://codes-sources.commentcamarche.net/forum/affich-10000111-plugin-better-cs-2#cptpingu-signature
0
Technoinfo Messages postés 362 Date d'inscription jeudi 6 octobre 2016 Statut Membre Dernière intervention 17 avril 2021
23 mars 2017 à 19:58
Désolé voila la bonne image :https://framapic.org/PSWpHfnYMUI4/wdQlFU1egu2N?t=
0
cptpingu Messages postés 3837 Date d'inscription dimanche 12 décembre 2004 Statut Modérateur Dernière intervention 28 mars 2023 123
24 mars 2017 à 11:28
Les fichiers include sont bien trouvés, mais tu as un souci de link. Donc les bibliothèques ne sont pas trouvées correctement.
Que renvoie la commande "pkg-config --libs --cflags gtk+-3.0" ?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Technoinfo Messages postés 362 Date d'inscription jeudi 6 octobre 2016 Statut Membre Dernière intervention 17 avril 2021
24 mars 2017 à 11:48
Je suis sous windows.
J'essai ce soir quand je serrai sous linux.
Cordialement.
Technoinfo.
0
Technoinfo Messages postés 362 Date d'inscription jeudi 6 octobre 2016 Statut Membre Dernière intervention 17 avril 2021
Modifié le 25 mars 2017 à 00:24
La Commande donne :
-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0
-I/usr/include/dbus-1.0 -I/usr/lib/i386-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0
-I/usr/include/gio-unix-2.0/ -I/usr/include/mirclient -I/usr/include/mircommon -I/usr/include/mircookie
-I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0
-I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2
-I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0
-I/usr/lib/i386-linux-gnu/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0
-lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

Linux+Windows=Dual boot
0
Technoinfo Messages postés 362 Date d'inscription jeudi 6 octobre 2016 Statut Membre Dernière intervention 17 avril 2021
25 mars 2017 à 18:06
J'ai réussi a compiler avec cette commande :
gcc main.c $(pkg-config --cflags --libs gtk+-3.0) -o main

Cordialement.
Technoinfo.
0
Rejoignez-nous