-1

I'm new at C and started to learn how to create GUI. For some reason the only way program run is

 gcc simple.c -o simple -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12

If i just run gcc simple.cit gives me

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/glib-2.0/gobject/gbinding.h:28,
             from /usr/include/glib-2.0/glib-object.h:23,
             from /usr/include/glib-2.0/gio/gioenums.h:28,
             from /usr/include/glib-2.0/gio/giotypes.h:28,
             from /usr/include/glib-2.0/gio/gio.h:26,
             from /usr/include/gtk-2.0/gdk/gdkapplaunchcontext.h:30,
             from /usr/include/gtk-2.0/gdk/gdk.h:32,
             from /usr/include/gtk-2.0/gtk/gtk.h:32,
             from graphical.c:1:/usr/include/glib-2.0/glib/gtypes.h:32:24: fatal error: glibconfig.h: No such file or catalog compilation terminated.

If I do other 'traditional' ways to include lib:

gcc `pkg-config gtk+-2.0 --cflags` example.c -o example `pkg-config gtk+-2.0 --libs`

It gives me:

Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc' to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
graphical.c:1:21: fatal error: gtk/gtk.h: No such file or catalog

What is the right way to include GTK?

shegeley
  • 85
  • 2
  • 8
  • 2
    Possible duplicate of [How to compile C and Gtk+ with GCC on Linux?](http://stackoverflow.com/questions/14944866/how-to-compile-c-and-gtk-with-gcc-on-linux) – Scribblemacher Dec 02 '16 at 18:53
  • @Scribblemacher None of this ways works. – shegeley Dec 02 '16 at 19:02
  • @ГригорийШепелев Then it's probably too localized. – MD XF Dec 02 '16 at 19:16
  • 2
    Your first example tries to build with GTK+ 3, and your second example tries to build with GTK+ 2. You'll need to pick one. – andlabs Dec 02 '16 at 19:38
  • @andlabs Not working – shegeley Dec 02 '16 at 19:53
  • You still need to choose one. Which one do you want to use? GTK+ 2 and GTK+ 3 are **NOT** interchangeable; code written for one cannot work on the other without lots of changes. – andlabs Dec 02 '16 at 22:12
  • @andlabs I chose gtk3 last time. And it's still not working. – shegeley Dec 03 '16 at 07:22
  • I'm looking for solvation of this library problem for 3 days already. – shegeley Dec 03 '16 at 07:22
  • 1
    Then try `gcc \`pkg-config gtk+-3.0 --cflags\` example.c -o example \`pkg-config gtk+-3.0 --libs\``. – andlabs Dec 03 '16 at 07:31
  • @andlabs a bunch of errors like : «Package gtk+-3.0 was not found in the pkg-config search path» and «/usr/include/glib/gtypes.h:32:24: fatal error: no such file» – shegeley Dec 03 '16 at 07:39
  • 1
    Then you haven't installed the GTK+ 3 package. What development environment are you using? MSYS2? – andlabs Dec 03 '16 at 13:32
  • @andlabs Of course I installed GTK3+ lib. libgtk-3-dev:amd64 3.18.9-1ubuntu3.1. What do you mean saying 'development enviroment'? I use vim , zsh and tmux. – shegeley Dec 03 '16 at 17:53
  • 1
    Sorry; I confused this for another question. Very weird that you don't have the pkg-config files then. Is `$PKG_CONFIG_PATH` being overridden? – andlabs Dec 03 '16 at 18:18
  • @andlabs As I said previously I have problems with pkg-config. «echo $PKG_CONFIG_PATH» gives nothing. – shegeley Dec 03 '16 at 18:24
  • Then the pkg-config is using the default path. What do you see in /usr/lib/x86_64-linux-gnu/pkg-config? – andlabs Dec 03 '16 at 21:01
  • @andlabs oh, thanks. I found it. 'gtk+-3.0.pc' is right here. For some reason pkg-config doesn't find this path automatically. How can I save it? Add to .zshrc? – shegeley Dec 04 '16 at 06:34
  • @andlabs I just figured out what was the problem: I has linuxbrew installed and for some reason pkg-config took path from one of it's repos even if I force it to export. I completely removed linuxbrew and now it's finally working! :) – shegeley Dec 04 '16 at 06:52
  • Your `pkg-config` should use `gtk+-3.0` and you should install GTK3 development files (e.g. the `libgtk-3-dev` package on Debian or Ubuntu) – Basile Starynkevitch Dec 04 '16 at 07:18
  • @BasileStarynkevitch I know what should it be. Please read my answer to this question. – shegeley Dec 04 '16 at 07:19

1 Answers1

0

I just figured out what was the problem.

I had linuxbrew installed and for some reason pkg-config took path from one of it's repos even if I force it to export. I completely removed linuxbrew and now it's finally working!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
shegeley
  • 85
  • 2
  • 8