Author Topic: gtk+3 and code::blocks on linux  (Read 7673 times)

Offline niconol

  • Multiple posting newcomer
  • *
  • Posts: 16
gtk+3 and code::blocks on linux
« on: September 21, 2017, 03:04:07 pm »
Hi,
I'm trying to write my first project with gtk+3 on CB IDE. At the end, I'll want to design my windows from glade, but it's note the problem now. I'm working on raspbian.

I installed gtk+3 as this:
Code
sudo apt-get install libgtk-3-dev

I found the libraries location
Code
pi@raspberrypi:~ $ apt-file search gtk-3 | grep "gtk/gtk.h"
libgtk-3-dev: /usr/include/gtk-3.0/gtk/gtk.h
libgtk-3-dev: /usr/include/gtk-3.0/gtk/gtkcheckbutton.h
libgtk-3-dev: /usr/include/gtk-3.0/gtk/gtkcheckmenuitem.h
libgtk-3-dev: /usr/include/gtk-3.0/gtk/gtkshow.h

In CB 13.12, I open a new gtk project
The default main.c is:
Code
#include <stdlib.h>
#include <gtk/gtk.h>

static void helloWorld (GtkWidget *wid, GtkWidget *win)
{
  GtkWidget *dialog = NULL;

  dialog = gtk_message_dialog_new (GTK_WINDOW (win), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hello World!");
  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
  gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);
}

int main (int argc, char *argv[])
{
  GtkWidget *button = NULL;
  GtkWidget *win = NULL;
  GtkWidget *vbox = NULL;

  /* Initialize GTK+ */
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  /* Create the main window */
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (win), 8);
  gtk_window_set_title (GTK_WINDOW (win), "Hello World");
  gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
  gtk_widget_realize (win);
  g_signal_connect (win, "destroy", gtk_main_quit, NULL);

  /* Create a vertical box with buttons */
  vbox = gtk_vbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (win), vbox);

  button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  g_signal_connect (button, "clicked", gtk_main_quit, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

  /* Enter the main loop */
  gtk_widget_show_all (win);
  gtk_main ();
  return 0;
}

I add
Code
/usr/include/gtk-3.0
in gtk_pro (and in Debug end Realease)  -> search directories -> compiler, I add
Code
/usr/include/gtk-3.0

I compile, and there is a fatal error:
Code
-------------- Build: Debug in gtk_pro (compiler: GNU GCC Compiler)---------------

gcc -Wall -g -I/usr/include/gtk-3.0 -I/usr/include/gtk-3.0/gdk -c /home/pi/dic2/gtk_pro/main.c -o obj/Debug/main.o
In file included from /usr/include/gtk-3.0/gdk/gdk.h:30:0,
                 from /usr/include/gtk-3.0/gtk/gtk.h:30,
                 from /home/pi/dic2/gtk_pro/main.c:2:
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:18: fatal error: glib.h: No file or directory of this type (my own translation)
 #include <glib.h>
                  ^
compilation terminated.
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 0 warning(s) (0 minute(s), 1 second(s))

Now I include the directorie
Code
/usr/include/glib-2.0

fatal error:
Code
------------- Build: Debug in gtk_pro (compiler: GNU GCC Compiler)---------------

gcc -Wall -g -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 -c /home/pi/dic2/gtk_pro/main.c -o obj/Debug/main.o
In file included from /usr/include/glib-2.0/glib/galloca.h:32:0,
                 from /usr/include/glib-2.0/glib.h:30,
                 from /usr/include/gtk-3.0/gdk/gdkconfig.h:13,
                 from /usr/include/gtk-3.0/gdk/gdk.h:30,
                 from /usr/include/gtk-3.0/gtk/gtk.h:30,
                 from /home/pi/dic2/gtk_pro/main.c:2:
/usr/include/glib-2.0/glib/gtypes.h:32:24: fatal error: glibconfig.h: Aucun fichier ou dossier de ce type
 #include <glibconfig.h>
                        ^
compilation terminated.
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

I don't find this library.

Is there a simply way to find it, to specify all the directories if other are necessary, or more simply, start easly a project with gtk+3 ?

Best, and sorry for my poor english.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: gtk+3 and code::blocks on linux
« Reply #1 on: September 22, 2017, 12:08:26 am »
Best method on Linux (or similar) is to use pkg-config in the settings.
You can just use the appropriate pkg-config-command in backticks in "Other compiler options" and "Other linker options" in the "Build options" of your project.
In your cause probable `pkg-config gtk+-3.0 --cflags` and `pkg-config gtk+-3.0 --libs` .

Offline niconol

  • Multiple posting newcomer
  • *
  • Posts: 16
Re: gtk+3 and code::blocks on linux
« Reply #2 on: September 22, 2017, 10:54:51 am »
all right,
the project from template gtk+ can be compiled in this conditions.
Now I hav some problems because using gtk2 symbols and gtk3, it's not possible.
It's time to play for me with my own code.

Thanks a lot,

best